-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
this function argument type can not be narrowed to its subclass #35466
Comments
This is a correct error; in a derived class of |
Extra properties for derived class |
Again, this is a correct error. Extra properties is just one form of subtyping that could occur here. type Attributes<T> = {[P in keyof T]? : T[P]};
class A {
a: string = '';
setAttributes(attributes: Attributes<this>) {
}
}
class B extends A{
b: string = '';
async run(attributes: Attributes<B>) {
this.setAttributes(attributes)
}
}
class C extends B {
b: "foo" = "foo";
setAttributes(attributes: Attributes<this>) {
if (attributes.b !== undefined) {
// Must be true, but is false
console.log(attributes.b === "foo");
}
}
}
const b: B = new C();
b.run({ a: 'a', b: 'not foo' }); |
Wow! I see what you mean now, thanks for explanation. |
TypeScript Version: 3.5.3
Search Terms:
Code
Expected behavior:
No Error
Actual behavior:
I didn't find any way for this check to be relevant. If someone can point me out the use case where such check is required, please let me know.
Playground Link:
http://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=24&pc=1#code/C4TwDgpgBAgswCcCWAjArsCBnAPAFQD4oBeKAbwG0AFKJAOygGsIQB7AMyjwF0B+KAFxdq3AL4BuAFABjADYBDLFljlJUKFgjA4iVBmwAKefGTpMWITtP7cwABZIsBAJSr1oyR5kKlUAEJQEAAemHQAJsowZGpQiiB00lAIaHRGJnrmlulm2Dh+Lm7qUPaOAHSa2tk2abo5WM4xHqJAA
The text was updated successfully, but these errors were encountered: