Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types support for package exports #367

Open
augustjk opened this issue May 18, 2023 · 0 comments
Open

Types support for package exports #367

augustjk opened this issue May 18, 2023 · 0 comments

Comments

@augustjk
Copy link
Collaborator

Current support for @types packages is to just load the base packages into the project. The existing logic handles any dependency types, but is unable to handle types specified by package exports ("exports" field on the package.json).

For example, having the following package.json

{
  "dependencies": {
    "@types/react-dom": "^18"
  }
}

won't produce types for

import {createRoot} from 'react-dom/client';

because only the base @types/react-dom package's index.d.ts is loaded.

It is not able to resolve the ./client part from the package exports here: https://unpkg.com/@types/react-dom@18.2.4/package.json

In this particular case, a work around was available to add @types/react-dom/client as because they thankfully had a file called client.d.ts that the type resolver ended up adding to the project, and along with the package.json file from @types/react-dom, TS was able to resolve this.

Not sure exactly on best approach to support this.. A naive approach is to crawl the "exports" field of package.json and eagerly load all listed types. Or a smarter approach that handles the extra paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant