Closed
Description
TypeScript Version: 2.7.1
Search Terms:
property initialized used sub class
Code
class Super {
protected prop: { a: number; };
constructor() {
this.prop = { a: 1 };
}
}
class Sub extends Super {
protected prop: { a: number, b: number };
constructor() {
super();
this.prop = {
...this.prop,
b: 2
};
}
}
Expected behavior:
The assignment to this.prop
in the subclasss' constructor should succeed, with the compiler understanding that this.prop
, at that stage, has the value + type given to it by the superclass.
Actual behavior:
Error: Property 'prop' is used before being assigned.