microsoft / microsoft/TypeScript

`typesVersions` doesn't match behaviour of `exports`

Open
#56,957 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms
  • "typesVersions"
  • "exports"
🕗 Version & Regression Information
  • This relates to the work around Node.js exports (i.e. #53116).
  • This has never worked to my knowledge.
⏯ Playground Link

No response

💻 Code

package.json:

{
  "exports": {
    "./*": {
      "types": "./dist/types/*/*.d.ts",
      "import": "./dist/esm/*/*.js",
      "require": "./dist/cjs/*/*.js"
    }
  },
  "typesVersions": {
    "*": {
      "*": [
        "./dist/types/*/*.d.ts"
      ]
    }
  }
}
🙁 Actual behavior

These provided export paths work as expected in Node.js. For example, I can import from foo/dist/esm/bar/bar.js with:

import { bar } from 'foo/bar';

However, TypeScript is unable to resolve the double wildcard in typesVersions. I also see a validation error on the string ("./dist/types/*/*.d.ts") in VS Code.

🙂 Expected behavior

I'd expect that typesVersions behaves the same way that exports does.

Additional information about the issue

I realise that a quick solution to this would be to use index.js in each folder instead of a file with the same name as the folder, but wanted to report the different in behaviour here.

This may also technically be a feature request.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the package.json example and reproduce resolution of the double wildcard in typesVersions against the corresponding exports pattern. Then trace TypeScript's module-resolution handling for these fields and its validation path. Done means the documented pattern is accepted and resolves consistently with the exports behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.