#default export usage with NodeNext?

11 messages · Page 1 of 1 (latest)

lyric pulsar
#

I have my moduleResolution set to NodeNext, and I'm importing an ESM package:

declare const got: import("./types").Got;
export default got;
import got from "got";

Now I think got should be the default export with type Got, but it's not. Typescript tells me it only has a property named default. So I can do got.default.post() but I can't do got.post(). What am I doing wrong here? Why do I have to explicitly specify .default in my code when what I'm doing is importing a default export?

I shall note that (got as any).post() works just fine at runtime, so it seems to be a typescript bug. I'm using Typescript 4.8.4.

upper sand
#

can you share your tsconfig?

lyric pulsar
#

sorry I missed the message somehow... here's the config:

{
  "extends": "./node_modules/@itwin/build-tools/tsconfig-base.json",
  "compilerOptions": {
    "alwaysStrict": true,
    "esModuleInterop": false,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "inlineSources": true,
    "jsx": "react",
    "noFallthroughCasesInSwitch": false,
    "noImplicitAny": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": false,
    "noUnusedParameters": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": true,
    "stripInternal": false,
    "target": "ES2019"
    "declaration": false,
    "declarationMap": false,
    "tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo",
    "outDir": "./lib",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "types": ["mocha", "node"],
    "allowSyntheticDefaultImports": true
  },
  "include": [
    "./src/**/*.ts*"
  ]
}
upper sand
lyric pulsar
#

🤔 thanks, I don't remember why that's there but I'll try to make my code work without it

lyric pulsar
lyric pulsar
#

for now I'm using this workaround:

import gotImport, { ... } from "got";
const got = gotImport.default;
vernal trellis
lyric pulsar
#

got is an npm package, I can't modify it

#

I just want to import it, I don't want to re-export