-
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
Consider contextually typing class member functions by their base class/interface members #1373
Comments
Contextual typing has only ever been applied to expressions and not statements so this has never worked. That said, it's certainly a reasonable thing to expect, at least for the function declaration style: class SortByQueryId implements ISortInfo {
getvalue(x) { /* x should be QuerySummary in here */ }
} Edited the title slightly to reflect this. |
Thanks Dan. I love this open community style development process :) |
Can the scope of this be expanded to support member properties and static properties? See my comment in #1887 for an example. |
Adding an example of broken return value inference that results in a compiler error: type Events = {
[event: string]: () => void;
};
class A {
getEvents(): Events {
return null;
}
}
class B extends A {
getEvents() {
return {
'click': () => {
}
};
}
}
// test.ts(12,7): error TS2415: Class 'B' incorrectly extends base class 'A'.
// Types of property 'getEvents' are incompatible.
// Type '() => { 'click': () => void; }' is not assignable to type '() => { [event: string]: () => void; }'.
// Type '{ 'click': () => void; }' is not assignable to type '{ [event: string]: () => void; }'.
// Index signature is missing in type '{ 'click': () => void; }'. |
+1 |
1 similar comment
+1 |
Approved. When a method has multiple parent declarations (e.g. implementing multiple interfaces which each have a method named the same thing), union them to provide a contextual type. |
This will be fixed by #6118. |
I'm also in support for extending it to base class members and statics. |
Unfortunately, we couldn't come up with a solution that was consistent and backward-compatible. See #6118 for details. I'm closing this for now. |
here is my code
when I type "x." I expect to see the properties of QuerySummary but I do not. VS still thinks the type is 'any'
The text was updated successfully, but these errors were encountered: