Pulling in ambient types through triple slash directive stopped working when exports field present on package.json #46860
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
π Search Terms
tripleslash ambient types
π Version & Regression Information
β― Playground Link
Not possible to show in the playground
π» Code
global.d.ts
/// <reference types="svelte" />
π Actual behavior
Since 4.5 referencing types via triple slash directives in an ambient module to pull in other ambient types into the global scope stopped working when the package whose types should be pulled in has
exports
defined in theirpackage.json
, but notypes
field insideexports
.π Expected behavior
Referencing types via triple slash directives should pull in their ambient types into the global scope
Steps to reproduce
This is reproducible using the Svelte starter template which uses this technique to tell TypeScript to treat any file import ending with
.svelte
as valid, resolving it to an ambient module named*.svelte
.npx degit sveltejs/template svelte-app
cd svelte-app/ && node scripts/setupTypeScript.js
- this converts the template to using TSpackage.json
pin thesvelte
version to3.44.1
(the last version where this occurs, we since added a fix on our side, but I still think this a TS bug)npm install
main.ts
--> bug:import App from './Apps.svelte';
has an error because the triple slash directive inglobal.d.ts
doesn't workIf I change the triple slash directive in
global.d.ts
to/// <reference path="../node_modules/svelte/types/runtime/index.d.ts" />
it works. That path reference is what thetypes
field in thepackage.json
of Svelte resolves to, so I would expect/// <reference types="svelte" />
to work.My guess is that this is a side effect of the new Node12 mode which was part of the 4.5 beta releases but was then pulled out of the final release. With that new mode it would be expected to have a corresponding
types
entry as part of theexports
in Svelte'spackage.json
, but since that new resolution isn't used I would expect the types to get resolved like in 4.4 and downwards. In fact, I just tested this out and it indeed works in 4.5 using/// <reference types="svelte" />
iftypes
is part of theexports
inpackage.json
.I guess this not only impacts the Svelte starter template but every package which has
exports
withouttypes
in it and wants to support loading definitions into the global scope through tripleslash directives.The text was updated successfully, but these errors were encountered: