- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis
Milestone
Description
TypeScript Version: 3.3.0-dev.20181212
readonly if
Code
interfaceIProps{foo1?: string;foo2: string;}classFoo<P>{protectedprops: Readonly<P>;constructor(props: Readonly<P>){this.props=props;}}classBar<PextendsIProps>extendsFoo<P>{privatetest1(){const{ foo1, foo2 }=this.props;if(foo1){foo1.toUpperCase();// finethis.test2(foo1);// error "Type undefined is not assignable to type string"}this.test2(foo2);// fine}privatetest2(foo: string): void{}}Expected behavior:
I expect the above to compile without error
Actual behavior:
There's an error - Type 'undefined' is not assignable to type 'string'
"foo1" above can't be undefined because it's within an "if (foo1){}".
Playground
link
aoberoi
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis