Microsoft/TypeScript
Auf GitHub ansehenOverriding generic method inconsistently errors
Open
#26.631 geöffnet am 23. Aug. 2018
BugDomain: check: Variance RelationshipsHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms: override generic
Code
interface Foo {
method<T>(): T;
}
// Error: Interface 'Bar<T>' incorrectly extends interface 'Foo'.
interface Bar<T extends Node> extends Foo {
method<T2 extends T>(): T2;
}
// Uncommenting this suddenly fixes the error
// interface Foo {
// method<T>(): T;
// }
Full error message:
Interface 'Bar<T>' incorrectly extends interface 'Foo'.
Types of property 'method' are incompatible.
Type '<T2 extends T>() => T2' is not assignable to type '<T>() => T'.
Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated.
Type 'Node' is not assignable to type 'T'.
Expected behavior: The error should always appear, or always not appear.
Actual behavior: A partial interface mysteriously removes the error
Related Issues: #23960