jimmywarting / native-file-system-adapter

File system, based on the spec reference implementation

Home Page:https://jimmywarting.github.io/native-file-system-adapter/example/test.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeScript types are not working

moltar opened this issue · comments

commented

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

commented

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

commented

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';

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

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