jimmywarting / native-file-system-adapter

File system, based on the spec reference implementation
https://jimmywarting.github.io/native-file-system-adapter/example/test.html
MIT License
484 stars 43 forks source link

TypeScript types are not working #50

Open moltar opened 1 year ago

moltar commented 1 year ago

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

djpetti commented 1 year ago

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.

AviDuda commented 1 year ago

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";
}
linonetwo commented 1 year ago

@jimmywarting Helps, please release a new version!

jcbhmr commented 1 year ago

@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.

jimmywarting commented 1 year ago

maybe. don't care so much where they end up anyway. they are auto generated when publishing anyway

ChasonZheng commented 1 year ago

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

creatxrgithub commented 10 months ago

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';
spookyuser commented 9 months ago

Here's a patch for pnpm

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 :)

eavonius commented 7 months ago

This is fixed in the main trunk, can we get a release to npm?