You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS: import() type in a JSDoc cast under a top-level await reports TS2307 #65728
In a JS file, the module of an import() type written in a JSDoc type cast is not resolved when the cast is inside a top-level await expression. The cast then has an error type, so nothing that uses the value is checked.
Both files report the type error, as typescript@5.9.3 does:
awaited.js(2,9): error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
plain.js(2,9): error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
Actual
awaited.js(1,39): error TS2307: Cannot find module './b' or its corresponding type declarations.
plain.js(2,9): error TS2551: Property 'toFixed' does not exist on type 'string'. Did you mean 'fixed'?
Notes (each verified by changing only that part):
A package specifier fails the same way as the relative one.
The cast can be anywhere under the await: await [cast] and await (() => { var a = cast; })() fail too. await Promise.resolve(cast) resolves.
Only a top-level await is affected: the same statement inside async function f() { … } resolves.
Only the cast form is affected: await (async () => { /** @type {import("./b").B} */ let a; })() resolves.
A @satisfies cast fails too: await (() => { var a = /** @satisfies {import("./b").B} */ ({ b: "" }); })().
In a .ts file, await (async () => { var a = {} as import("./b").B; })() resolves.
Environment
typescript@7.1.0-beta; also reproduces with typescript@7.0.2 and typescript@7.1.0-dev.20261129.1
typescript@5.9.3: no TS2307, both files report TS2551
Activity