Microsoft/TypeScript
GitHub ã§èŠã`export let` variable doesn't require the variable to be assigned within current file
Open
#61,994 opened on 2025幎7æ3æ¥
Domain: check: Control FlowHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
export let, undefined, assignment, assigned
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
export let
⯠Playground Link
No response
ð» Code
// a.ts
export let x: { foo(): void }
if (!!false) {
// @ts-expect-error Variable 'x' is used before being assigned.
x.foo()
}
// b.ts
import { x } from './a.ts'
// TS compiles, throws at runtime
x.foo()
ð Actual behavior
TS compiles, only throws at runtime.
ð Expected behavior
TS refuses to compile without ! non-null assertion, with error probably being reported in the exporting module a.ts rather than the importing module b.ts.
Additional information about the issue
No response