js-kubo-rpc-client
js-kubo-rpc-client copied to clipboard
[TypeScript] Types not available when moduleResolution = Node16/NodeNext
Steps to reproduce
- Configure a new TypeScript project with
kubo-rpc-client
as dependency and the followingtsconfig.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
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
.
+1, we've encountered this problem as well
+1
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.