Closed
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