microsoft / microsoft/TypeScript

overload + generic + infer breaks conditional types

Open
#39,767 1 comment 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.