js-kubo-rpc-client icon indicating copy to clipboard operation
js-kubo-rpc-client copied to clipboard

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

Open mirayashi opened this issue 1 year ago • 3 comments

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.

mirayashi avatar Aug 25 '23 18:08 mirayashi

+1, we've encountered this problem as well

Rinse12 avatar Feb 06 '24 16:02 Rinse12

+1

TheRealSmeddy avatar Mar 26 '24 14:03 TheRealSmeddy

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.

achingbrain avatar Apr 18 '24 12:04 achingbrain