You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use this package with a Typescript setup with node. I'd like to use the Typescript typing information and modern module syntax, i.e. import { ... } from 'postgres' instead of ... = require('postgres'), and I'm running into issues and would like your advice.
Using the module import syntax, I'm able to retrieve all type information for Typescript, as the import seems to pull from the typing file directly:
But from here, I can't figure out how to use the library. Intellisense doesn't find the typical postgres(...) function that's demo'd in the README. Trying to use the import as-is results in a Typescript build error:
On the other side, if I use the require syntax, I'm able to use the library as normal, but then I'm not sure how to get the type information:
I'm not allowed to use both importing styles together, so I can't do them both to get the library implementation and types.
Please let me know if I'm missing something obvious or using the library incorrectly.
I'm using the 2.0.0-beta.2 release.
node --version: v15.0.1
The text was updated successfully, but these errors were encountered:
@AnthonyMonterrosa TLDR: Add "allowSyntheticDefaultImports": true, in your tsconfig.json, then import PostgreSQL from 'postgres'
postgres has the same problem as many CommonJS packages: it directly expose an augmented function with additionnal properties (postgres.BigInt, etc.), so neither import { ... } from 'postgres', import PostgreSQL from 'postgres' nor import * as PostgreSQL from 'postgres' can work properly. TypeScript designers addressed the issue by adding the allowSyntheticDefaultImports property in tsconfig.json to allow import postgres from 'postgres' to work but no longer complies with the ES module specification (the default import should come from module.exports.default but postgres override directly module.exports).
@porsager This is not mentioned in the README. Is this an oversight? #84 adds TypeScript tips in README, maybe I can add this one too.
I'm trying to use this package with a Typescript setup with node. I'd like to use the Typescript typing information and modern module syntax, i.e.
import { ... } from 'postgres'
instead of... = require('postgres')
, and I'm running into issues and would like your advice.Using the module




import
syntax, I'm able to retrieve all type information for Typescript, as the import seems to pull from the typing file directly:But from here, I can't figure out how to use the library. Intellisense doesn't find the typical
postgres(...)
function that's demo'd in the README. Trying to use the import as-is results in a Typescript build error:On the other side, if I use the

require
syntax, I'm able to use the library as normal, but then I'm not sure how to get the type information:I'm not allowed to use both importing styles together, so I can't do them both to get the library implementation and types.
Please let me know if I'm missing something obvious or using the library incorrectly.
I'm using the
2.0.0-beta.2
release.node --version
:v15.0.1
The text was updated successfully, but these errors were encountered: