Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default export type not being picked up with module: "nodenext" #2208

Closed
wight554 opened this issue Oct 22, 2022 · 4 comments · Fixed by #2695
Closed

Default export type not being picked up with module: "nodenext" #2208

wight554 opened this issue Oct 22, 2022 · 4 comments · Fixed by #2695

Comments

@wight554
Copy link

wight554 commented Oct 22, 2022

Bug report

Description / Observed Behavior

When trying to use imported useSWR hook I'm getting the following error:

import useSWR
This expression is not callable.
  Type 'typeof import("/Users/Volodymyr_Zhdanov/playground/blog-template/node_modules/swr/dist/index")' has no call signatures.

Expected Behavior

Import should pick-up typings

Repro Steps / Code Example

  1. Add these settings to tsconfig:
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
  1. Add "type": "module" to package.json
  2. Import and use useSWR hook
  3. See the error

Additional Context

SWR version: ^1.3.0
Typescript version: ^4.8.4

3 possible fixes:

  1. Add named export for useSWR
  2. Use CJS styled export in typings: export default useSWR; => export = useSWR;
  3. Use declaration merging to make default export namespace and function simultaneously, example here: make type definitons "module": "nodenext" compatible fastify/fastify-cookie#184
@promer94
Copy link
Collaborator

Ref: microsoft/TypeScript#50466

@wight554
Copy link
Author

Ref: microsoft/TypeScript#50466

This can be referenced as well: microsoft/TypeScript#48845

@promer94
Copy link
Collaborator

After TypeScript 5.0 got released.

This could be a workaround

{
  "compilerOptions": {
    "moduleResolution": "bundler",
   }
}

https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#moduleresolution-bundler

@dubiousdavid
Copy link

This still doesn't work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants