-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Strange error implementing interface with class expression #19853
Copy link
Copy link
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: typescript@2.7.0-dev.20171108
Code
export interface I<T> {
one(): T | undefined;
many(): T[];
}
function f(): { new<T>(): I<T> } {
return class X<T> {
one(): T { return <any>null; }
many(): T[] { return <any>null; }
};
}Expected behavior:
No error.
Actual behavior:
src/a.ts(7,2): error TS2322: Type 'typeof X' is not assignable to type 'new <T>() => I<T>'.
Type 'X<T | undefined>' is not assignable to type 'I<T>'.
Types of property 'many' are incompatible.
Type '() => (T | undefined)[]' is not assignable to type '() => T[]'.
Type '(T | undefined)[]' is not assignable to type 'T[]'.
Type 'T | undefined' is not assignable to type 'T'.
Type 'undefined' is not assignable to type 'T'.We get the error in many() despite one() being the method with a different return type.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed