- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped types
Milestone
Description
TypeScript Version: 3.3.0-dev.20181212
readonly if
Code
interface IProps { foo1?: string; foo2: string; } class Foo<P> { protected props: Readonly<P>; constructor(props: Readonly<P>) { this.props = props; } } class Bar<P extends IProps> extends Foo<P> { private test1() { const { foo1, foo2 } = this.props; if (foo1) { foo1.toUpperCase(); // fine this.test2(foo1); // error "Type undefined is not assignable to type string" } this.test2(foo2); // fine } private test2(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: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped types