-
Notifications
You must be signed in to change notification settings - Fork 12.8k
strictPropertyInitialization with subclasses that refine the types of properties #20911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Seems undesirable. CC @ahejlsberg. |
Note: this is not the case in TypeScript's implementation, but in the current stage-3 class properties, This does mean that, in a stage-3 compliant implementation, |
@Kovensky Huh! Reading through: https://tc39.github.io/proposal-class-fields/#initialize-public-instance-fields it seems like What the code is trying to do is declare the type of the existing field rather than declaring the field itself. This works today and expresses that intent pretty well. Typescript even gives an error if the declared type of class A {
x: {y: string} = {y: 'y'};
}
class B extends A {
}
interface B {
x: {y: string, z?: number};
} I'd like someone else to double check my reasoning here, but if all of the above is correct then I think this issue can be closed as working correctly. |
Ryan posted a very helpful suggestion over in #35831. If you're using at least TS 3.7, there's a |
TypeScript Version: 2.7.0-dev.20171226
Code
Expected behavior:
I expected this not to warn because
A#x
is assignable toB#x
.Actual behavior:
The text was updated successfully, but these errors were encountered: