microsoft / microsoft/TypeScript
Type with overloaded method with a generic overload matches type with incompatible method
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.0-dev.20200305
Search Terms:
generic type overload
Code
interface I1 {
f<V extends 'a'>(value: V): void;
f(value: 'b'): void;
}
interface I2 {
f(value: 'c'): void;
}
function test(x: I1) {
function u(y: I2) { }
u(x);
}
Expected behavior:
Compilation error, u cannot accept x as I1 cannot handle f('c')
Actual behavior:
Compilation succeeds.
Note that all of the following fail, as expected:
interface I1 {
// f<V extends 'a'>(value: V): void;
f(value: 'b'): void;
}
interface I2 {
f(value: 'c'): void;
}
function test(x: I1) {
function u(y: I2) { }
u(x);
}
interface I1 {
f<V extends 'a'>(value: V): void;
// f(value: 'b'): void;
}
interface I2 {
f(value: 'c'): void;
}
function test(x: I1) {
function u(y: I2) { }
u(x);
}
interface I1 {
f(value: 'a'): void;
f(value: 'b'): void;
}
interface I2 {
f(value: 'c'): void;
}
function test(x: I1) {
function u(y: I2) { }
u(x);
}
Related Issues:
Not sure.
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
Start with the TypeScript 3.9.0-dev.20200305 compiler and the minimal interfaces and call in the issue, using the linked Playground example to reproduce the successful assignment. Confirm that the generic and non-generic overload combination incorrectly accepts I1 as I2, then add a regression test and verify that the call produces the expected compilation error.
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
- Mostly clear
- Newbie friendliness
- 35/100