microsoft / microsoft/TypeScript
Overriding generic method inconsistently errors
Open
Nobody has claimed this yet.
Bug
Domain: check: Variance Relationships
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example from the Playground link in TypeScript 3.1.0-dev.201xxxxx, then compare it with and without the repeated Foo declaration. Read related issue #23960 for context; the work is done when the generic override either consistently reports the incompatibility or consistently accepts it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100