Closed
Description
TypeScript Version: 3.5.3
Search Terms:
property inheritance type override
Code
class A {
params: {} = {}
resetParams() {
this.params = {};
}
}
class B extends A {
params: {b: number} = {b: 1};
}
const b = new B()
b.params // => {b: 1};
b.resetParams();
b.params // => {};
Expected behavior:
A type of params
is strictly checked for incorrect assignment.
I do not see any solution to this myself other than disallow to override property type.
We can search how such cases are handled in other statically typed language like Java.
Actual behavior:
Typescript allows incorrect value assignment without any error.
Related Issues:
In this issue, there is an example where typescript tracks a possibility of property type being override and rejects to compile: #35466
Metadata
Metadata
Assignees
Labels
No labels