-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Extended class seems to automatically also turn properties into open records #44941
Comments
Duplicate of #10570. In your |
Thanks! I was sure an issue already existed but I couldn’t find it Yes, that’s the unexpected part. If Villa extends House, then I expect
|
It might help to understand that the reason that In the case of If you remove the |
Wow I never knew that TS would treat |
Closing as it matches #10570 It seems that using property assignments like that essentially sets the types as well, which sounds like a feature more than a bug 😰 class Villa extends House {
owner = {
names: ['Johnny'],
otherUnrelatedProperties: ':( accepted',
};
constructor() {
super();
this.owner = {
names: ['Johnny'],
otherUnrelatedProperties: ':( totally still accepted',
};
}
} So this is "the right way" to set properties in an extended class without changing the parent’s types: // otherUnrelatedProperties is rejected in the constructor 🎉
class Villa extends House {
constructor() {
super();
this.owner = {
names: ['Johnny'],
otherUnrelatedProperties: ':) rejected',
};
}
} |
Bug Report
🔎 Search Terms
class extended properties interface open record key
🕗 Version & Regression Information
I tried the latest (v4.3.5) and v3.6
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
otherUnrelatedProperties
was accepted on a property of type Person.names
is correctly required by TypeScript, so Person is being correctly set.The type of the
owner
property appears to be:🙂 Expected behavior
otherUnrelatedProperties
should not be accepted on theowner
property.The text was updated successfully, but these errors were encountered: