Skip to content

fix: import a declaration file package by the name it provides types for - #511

Merged
dsherret merged 4 commits into
denoland:mainfrom
dsherret:fix_types_package_specifier
Jul 27, 2026
Merged

fix: import a declaration file package by the name it provides types for#511
dsherret merged 4 commits into
denoland:mainfrom
dsherret:fix_types_package_specifier

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

Closes #457
Closes #402

A deno.json mapping a specifier to a types only package:

{
  "imports": {
    "unist": "npm:@types/unist@3.0.3"
  }
}

...emitted import type { Node } from "@types/unist", which TypeScript rejects:

error TS6137: Cannot import type declaration files. Consider importing 'unist' instead of '@types/unist'.

Now the name of the package the declarations are for is emitted instead (unist), which is how TypeScript resolves an @types/ package. The DefinitelyTyped scope encoding is undone as well, so @types/babel__core is imported as @babel/core. The package.json dependency keeps the real package name.

Added tests/types_package_project, which type checks the output, since that's what the issues report failing.

dsherret added 4 commits July 26, 2026 20:18
TypeScript errors when an `@types/` package is imported directly
(TS6137), so emit the name of the package it provides the declarations
for instead (ex. `@types/unist` -> `unist`).

Closes denoland#457
Closes denoland#402
- move the helper to the bottom with the other private helpers
- add unit tests and an end to end project that type checks the output
- document the behavior on the mapping option
@dsherret
dsherret merged commit ab8e2a4 into denoland:main Jul 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant