microsoft / microsoft/TypeScript
Uninitialized local check still permits provably erroneous use-before-assign in closure
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
uninitialized, local, use before assign, control flow
🕗 Version & Regression Information
- This changed in commit or PR https://github.com/microsoft/TypeScript/pull/55887
⏯ Playground Link
💻 Code
let foo: string;
const setFoo = (): void => {
if (foo.length < 1) {
foo = 'foo';
}
};
export {}
🙁 Actual behavior
No TS Error
🙂 Expected behavior
Variable 'foo' is used before being assigned.(2454)
Additional information about the issue
(this error is correctly reported if we never assign at all, as below)
let foo: string;
const setFoo = (): void => {
if (foo.length < 1) {
}
};
export {}
Related, https://github.com/microsoft/TypeScript/issues/60064.
Otherwise this can be solved by not considering assignments which occur unconditionally after a read.
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 linked TypeScript Playground reproduction and compare it with the additional example that already reports diagnostic 2454. Read the control-flow change in PR 55887 and related issue 60064; done means the closure read reports use-before-assign without breaking the existing no-assignment diagnostic behavior.
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