microsoft / microsoft/TypeScript
overload + generic + infer breaks conditional types
Open
Nobody has claimed this yet.
Bug
Domain: Conditional Types
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.2, 4.0.0-beta (playground), 3.9.6, 3.9.7 (locally tested)
Search Terms: overload generic conditional
Code
type Wrap <T> = T & { wrap: T }
interface Data { id: number }
interface Foo {
<K extends keyof Data> (): Wrap<Pick<Data, K>>;
<K extends keyof Data> (): Wrap<Pick<Data, K>>;
}
type A = Foo extends (...args: any[]) => infer R ? 1 : 0;
type B = Foo extends (...args: any[]) => any ? 1 : 0;
declare let a: A, b: B;
a = b // Type '1' is not assignable to type '0'.(2322)
Expected behavior: compiles without error
Actual behavior: Type '1' is not assignable to type '0'
Playground Link: Link
Related Issues:
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 minimal example in the linked TypeScript Playground using the listed compiler versions, then trace how the overload, generic inference, and conditional type are evaluated. Done means the example compiles without the reported assignment error while preserving the expected results for A and B.
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