GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing github.com — Add import assertions to type only imports and import types to force the resolution mode of the specifier by weswigham · Pull Request #47807 · microsoft/TypeScript Conversation
|
|
FYI the PR description claims "Fixes #47807", but this PR has number 47807 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
45e3c3d to
355ae11
Compare
355ae11 to
476dc6d
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
This feels really wrong 😕 The proposal explicitly says that import 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 proposal even 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Wesley Wigham (@weswigham) This is wrong, we're using the There are plenty of other options that make sense without completely new and ts-only syntax e.g. // comment directive, nothing new // @ts-resolution=require import type { RequireInterface } from "pkg"; // https://github.com/tc39/proposal-import-reflection import type { RequireInterface } from "pkg" as "resolution=require"; // dangles off the already ts-only part import type(resolution=require) { RequireInterface } from "pkg"; Please consider reverting this change. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 in https://github.com/tc39/proposal-import-reflection. It would be a shame to see TS fostering that misconception, or perhaps falling victim to it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Why is it: assert {"resolution-mode": "import"}; (requiring quotes), and not: assert {resolutionMode: "import"}; ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Consistency with the triple-slash reference form and a bit of extra syntax encumbrance to make you pause and think if you really need to use it. :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
error importing type from esm in commonjs Allow synchronous type-only import of ESM package from CJS
There was an error while loading. Please reload this page.