antfu-collective / local-pkg

Get information on local packages.
MIT License
144 stars 15 forks source link

fix: add types to exports #6

Closed xeho91 closed 1 year ago

xeho91 commented 1 year ago

Description

In one of my projects, I have noticed that when importing your package, I get warning info from TypeScript (from the LSP -tsserver - to be more specific) that it cannot find the types, even though they exist in your repository in ./index.d.ts.

Warning: Could not find a declaration file for module 'local-pkg'. '/home/xeho91/Projects/terminal-nerds/configs/node_modules/.pnpm/local-pkg@0.4.2/node_modules/local-pkg/index.mjs' implicitly has an 'any' type. Try npm i --save-dev @types/local-pkg if it exists or add a new declaration (.d.ts) file containing declare module 'local-pkg';

My project has tsconfig.json with the following field set to:

// tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "NodeNext"
  }
}

Of course, when using "moduleResolution": "Node", there's no problem, but I can't change this field for some reasons.


So, along with this PR, I am adding a very simple fix to add types to the exports field object in ./package.json file. I have tested it by manually editing the package.json file inside ./node_modules/local-pkg/package.json inside my project directory. The warning is gone, and the types works. :man_shrugging:

Linked Issues

None.

Additional context

More information about this from the TypeScript blog - v4.7