microsoft / microsoft/TypeScript
`export let` variable doesn't require the variable to be assigned within current file
Open
Nobody has claimed this yet.
Domain: check: Control Flow
Help Wanted
Possible Improvement
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the cross-file example in a.ts and b.ts and reproduce the current compilation and runtime behavior. Trace the definite-assignment check for the exported x and its use after import; done means the compiler reports the missing assignment rather than allowing the runtime failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100