google / google/playground-elements

Types support for package exports

Open
#367 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
648
Forks
61
PR merge metrics
No merged PRs in 30d

Description

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`
```json
{
"dependencies": {
"@types/react-dom": "^18"
}
}
```
won't produce types for
```ts
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.