Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling in ambient types through triple slash directive stopped working when exports field present on package.json #46860

Closed
dummdidumm opened this issue Nov 18, 2021 · 0 comments Β· Fixed by #47007
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@dummdidumm
Copy link

dummdidumm commented Nov 18, 2021

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.

  1. Clone https://github.com/sveltejs/template, for example through npx degit sveltejs/template svelte-app
  2. cd svelte-app/ && node scripts/setupTypeScript.js - this converts the template to using TS
  3. In the package.json pin the svelte version to 3.44.1 (the last version where this occurs, we since added a fix on our side, but I still think this a TS bug)
  4. npm install
  5. Open project in VS Code and set TS to use the workspace TS version
  6. Open main.ts --> bug: import App from './Apps.svelte'; has an error because the triple slash directive in global.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.

dummdidumm added a commit to sveltejs/svelte that referenced this issue Nov 18, 2021
This will be needed when TS adds the new node module resolution algorithm. It also solves microsoft/TypeScript#46860 on our end.
dummdidumm added a commit to sveltejs/svelte that referenced this issue Nov 19, 2021
This will be needed when TS adds the new node module resolution algorithm. It also solves microsoft/TypeScript#46860 on our end.

Closes #6939
thetutlage added a commit to adonisjs/core that referenced this issue Nov 21, 2021
Our lovely TypeScript is finding every possible way to break things on every release.
I cannot find any documentation on "export maps" behavior, except these issues

microsoft/TypeScript#46860
microsoft/TypeScript#46334
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Nov 22, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.6.0 milestone Nov 22, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Dec 3, 2021
hakula139 added a commit to hakula139/careecuz-frontend that referenced this issue Dec 22, 2021
hakula139 added a commit to hakula139/vue-ts-app-template that referenced this issue Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants