Description
Bug Report
π Search Terms
tripleslash ambient types
π Version & Regression Information
- This changed between the latest version o 4.4 and 4.5.2
β― 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 their package.json
, but no types
field inside exports
.
π 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
.
- Clone https://github.com/sveltejs/template, for example through
npx degit sveltejs/template svelte-app
cd svelte-app/ && node scripts/setupTypeScript.js
- this converts the template to using TS- In the
package.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
- Open project in VS Code and set TS to use the workspace TS version
- Open
main.ts
--> bug:import App from './Apps.svelte';
has an error because the triple slash directive inglobal.d.ts
doesn't work
If 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 the types
field in the package.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 the exports
in Svelte's package.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" />
if types
is part of the exports
in package.json
.
I guess this not only impacts the Svelte starter template but every package which has exports
without types
in it and wants to support loading definitions into the global scope through tripleslash directives.