TypeScript types are not working
moltar opened this issue · comments
When I install native-file-system-adapter@3.0.0
, I still get the type errors:
Could not find a declaration file for module 'native-file-system-adapter'. '.../node_modules/native-file-system-adapter/src/es6.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/native-file-system-adapter` if it exists or add a new declaration (.d.ts) file containing `declare module 'native-file-system-adapter';`ts(7016
Related issue: #39
I fixed this by editing the "types"
key in node_modules/native-file-system-adapter/package.json
, and removing the leading slash in front of "types/mod.d.ts"
. It looks like this is fixed in master
.
In the meantime, you can fix types in your project by adding this to a file named e.g. native-file-system-adapter.d.ts
:
declare module "native-file-system-adapter" {
export * from "native-file-system-adapter/types/mod";
}
@jimmywarting Helps, please release a new version!
@jimmywarting Would it be worthwhile to put the .d.ts files right next to the corresponding .js files so that the automatic sibling .d.ts detection works? 🤔 Then you wouldn't need any custom types: ...
exports since any TS tool will just look for a same-name file with .replace(".js", ".d.ts")
~ish logic.
maybe. don't care so much where they end up anyway. they are auto generated when publishing anyway
In the meantime, you can fix types in your project by adding this to a file named e.g.
native-file-system-adapter.d.ts
:declare module "native-file-system-adapter" { export * from "native-file-system-adapter/types/mod"; }
it worked
in package.json modify the value
"types": "../types/mod.d.ts",
now, it works:
import { showDirectoryPicker, showOpenFilePicker } from 'native-file-system-adapter/mod';
or modify package.json
"types": "./types/mod.d.ts",
now, it works:
import { showDirectoryPicker, showOpenFilePicker } from 'native-file-system-adapter';
Just save it in a folder called patches, next to your project package.json, then pnpm i native-file-system-adapter
like normal and it should fix the types :)
This is fixed in the main trunk, can we get a release to npm?