-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π Search Terms
uninitialized, local, use before assign, control flow
π Version & Regression Information
- This changed in commit or PR error on variables that are used but never initializedΒ #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, #60064.
Otherwise this can be solved by not considering assignments which occur unconditionally after a read.
amongonz and ylc395
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript