- Notifications
You must be signed in to change notification settings - Fork13.2k
Add import assertions to type only imports and import types to force the resolution mode of the specifier#47807
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmitErrors1(module=node12).js OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
TimvdLippe commentedFeb 12, 2022
FYI the PR description claims "Fixes#47807", but this PR has number 47807 |
45e3c3d to355ae11Compare355ae11 to476dc6dCompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nicolo-ribaudo commentedMar 30, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This feels really wrong 😕 The proposal explicitly says thatimport assertions must not affect how a module is evaluated or resolved:
In other words, if both these two imports succeed they must resolve/evaluate the same file: import{A}from"pkg"assert{"resolution-mode":"require"};import{A}from"pkg"assert{"resolution-mode":"import"}; The imports assertions proposaleven mentions a possible follow-up proposal that would allow what you need, but it would be a separate proposal (with likely different syntax). I know that this PR is only about |
nicolo-ribaudo commentedMar 30, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
https://github.com/tc39/proposal-import-reflection is probably what you need, even if it's not clear yet if it's also meant to affect resolution. |
weswigham commentedMar 30, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
These don't affect runtime and are type-only (your example above doesn't work - you have to say |
nayeemrmn commentedApr 9, 2022
@weswigham This is wrong, we're using the There are plenty of other options that make sense withoutcompletely new and ts-only syntax e.g. // comment directive, nothing new//@ts-resolution=requireimporttype{RequireInterface}from"pkg"; // https://github.com/tc39/proposal-import-reflectionimporttype{RequireInterface}from"pkg"as"resolution=require"; // dangles off the already ts-only partimporttype(resolution=require){RequireInterface}from"pkg"; Please consider reverting this change. |
nayeemrmn commentedApr 9, 2022
I've already seen a lot of people confused by import assertions and what they could be used for in runtimes, specifically conflating them with what's proposed inhttps://github.com/tc39/proposal-import-reflection. It would be a shame to see TS fostering that misconception, or perhaps falling victim to it. |
glen-84 commentedApr 9, 2022
Why is it: assert{"resolution-mode":"import"}; (requiring quotes), and not: assert{resolutionMode:"import"}; ? |
weswigham commentedApr 9, 2022
Consistency with the triple-slash reference form and a bit of extra syntax encumbrance to make you pause and think if youreally need to use it. :) |
frehner commentedOct 8, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Would this also hypothetically help solve the issue found at#46213 ? If so, how soon do you think this feature will graduate from nightly? |
Uh oh!
There was an error while loading.Please reload this page.
This PR adds support for a TS-specific assertion on type-only imports and on import type nodes which forces the resolver into either
requireorimportresolution mode, allowing access to types which the containing file's default mode would normally make difficult or impossible to access. They look like this:This is essentially a continuation of#47732 that allows resolver configurability for more kinds of type-based imports. Since it's included in this PR, it'sprobably best to go and review & merge that first.
Fixes#47338 by allowing the types of an esm package to be fetched in a cjs file via these modal imports.
Fixes#47248