Closed
Description
Bug Report
π Search Terms
switch undefined
π Version & Regression Information
6.4 ~ 4.7.4 (latest)
β― Playground Link
Playground link with relevant code
π» Code
type State = {
foo: string
}
let state: State | undefined;
let result: boolean = false;
if (state) {
state.foo === "sdfdsf"
switch (true) {
case state.foo === 'test':
case state.foo === 'test':
result = true;
break;
// Object is possibly 'undefined'.ts(2532)
case state.foo === 'test':
case state.foo === 'test':
result = true;
break;
// Object is possibly 'undefined'.ts(2532)
case state && state.foo === 'test':
case state.foo === 'test':
result = true;
break;
// Object is possibly 'undefined'.ts(2532)
case state ? state.foo === 'test' : false:
case state.foo === 'test':
result = true;
break;
}
}
π Actual behavior
Error Object is possibly 'undefined'.ts(2532)
π Expected behavior
No error