xnimorz / use-debounce

A debounce hook for react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add types to package.json export

opened this issue · comments

Describe your idea

There are some useful types in the lib that users may want to import. However, some tools will not allow this given that the types are not declared in types referenced by package.json's exports field.

What's preventing exporting these types?

commented

Hey @edu-bound
I'm sorry but I'm not sure I clearly understand the issue, may I ask for some examples, please?

Sure. In package.json, the exports field is as follows,

{
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "import": "./esm/index.js",
      "require": "./lib/index.js"
    }
  }
}

Some tools recoginze the exports field and change their behavior based on its value. An example of such a tool is the ESLint plugin eslint-plugin-import-alias.

When a type not declared in the exports field is imported it, understandably, throws the following error,

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/useDebouncedCallback' is not defined by "exports" in /home/aryzing/workspace/project/node_modules/use-debounce/package.json

Therefore the ask is to please include useful types (in particular the one I'm after is DebouncedState<T>) in the exports fields. To TS consumers, it makes sense to have them as part of the package's exposed API.

Eg, with the current structure of the published package,

{
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "import": "./esm/index.js",
      "require": "./lib/index.js"
    },
    "./esm/useDebouncedCallback": {
      "import": "./esm/useDebouncedCallback.d.ts"
    }
  },
}
commented

got it, please, feel free to make a PR