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

[TypeScript] Types not available when moduleResolution = Node16/NodeNext #173

Open
mirayashi opened this issue Aug 25, 2023 · 3 comments
Open

Comments

@mirayashi
Copy link

mirayashi commented Aug 25, 2023

Steps to reproduce

  • Configure a new TypeScript project with kubo-rpc-client as dependency and the following tsconfig.json:
    "compilerOptions": {
      "target": "ES2022",
      "module": "ES2022",
      "moduleResolution": "Node16",
    }
    (NodeNext also does the thing)
  • Write a simple script using the library
    import { create } from 'kubo-rpc-client'
    import type { IPFSHTTPClient } from 'kubo-rpc-client'
    
    const client: IPFSHTTPClient = create()

Expected

I should get proper typings when importing the library

Actual

Everything is resolving as any and VSCode autocomplete doesn't work

Version Info

kubo-rpc-client version 3.0.1
VSCode version 1.81.1
Typescript version 5.1.6
node version 18.17.0

Screenshots

image

image

Workaround

A possible workaround for now is to change the moduleResolution to Bundler:

"compilerOptions": {
  "target": "ES2022",
  "module": "ES2022",
  "moduleResolution": "Bundler",
}

The downside is that you lose compile-time checking of import syntax. In ESM you are required to put file extensions (import { thing } from './myFile.js), however, Bundler allows you to just put ./myFile. So your code will compile without error, but you will still get an error at runtime because of lack of extension.

This might not be the only undesirable effect of using this setting. Ideally the types should be working just fine when using Node16/NodeNext.

@Rinse12
Copy link

Rinse12 commented Feb 6, 2024

+1, we've encountered this problem as well

@TheRealSmeddy
Copy link

+1

@achingbrain
Copy link
Member

achingbrain commented Apr 18, 2024

Please can you try with the latest release (e.g. 4.x.x)? Node16/NodeNext module resolution works for me now.

Note that the IPFSHTTPClient type has been renamed to KuboRPCClient so the script above needs a small edit.

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

No branches or pull requests

4 participants