-
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
Type inference regression with overloads #27972
Comments
This is working as intended. First, some clarifications. This is a change introduced in 3.1, not a new change in 3.2 as implied above, and the issue surfaces only in The change in 3.1 is that when, in Now, the real issue is that we only make inferences from the last overload because we're inferring from a type with two signatures to a type with only one signature. We've always had the rule that we match signatures pair-wise from the bottom when doing inference, so nothing new there. However, it means that nothing is or was ever inferred from the first overload, and it just so happened to work previously because we made a bad inference from the second overload. |
Hi, I think I have a related bug that is failing due to this issue: export interface DocumentType<T> {
hasKey(key: keyof T): boolean;
}
export interface DocumentTypeConstructor {
new<T>(value: T): DocumentType<T>;
}
export const DocumentType: DocumentTypeConstructor = class <T> {
private readonly value: T;
constructor(value: T) {
this.value = value;
}
hasKey(key: keyof T): boolean {
return key in this.value;
}
}; I get I found that the following code fixes the issue, but I don't understand why: export interface DocumentType<T> {
hasKey(key: keyof T): boolean;
}
export interface DocumentTypeConstructor {
new<T>(value: T): DocumentType<T>;
}
export const DocumentType: DocumentTypeConstructor = class <T> {
private readonly value: T;
constructor(value: T) {
this.value = value;
}
hasKey<TT extends keyof T>(key: TT): boolean {
return key in this.value;
}
}; The only difference is that I modified the signature of the implementation from |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.2.0-dev.20181018
Search Terms:
Code
Expected behavior:
No error, as in
typescript@3.1
.Actual behavior:
Looks like this was introduced by #27028. Discovered in
bluebird
on DefinitelyTyped -- in that case it had to do withtype CatchFilter<E> = (new (...args: any[]) => E) | ((error: E) => boolean) | (object & E);
which unions a construct and call signature which more clearly should be separate.The text was updated successfully, but these errors were encountered: