Skip to content

Exclude<keyof T, 'x'> should be assignable to Exclude<Exclude<keyof T, 'x'>, 'x'> #37768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
inga-lovinde opened this issue Apr 3, 2020 · 0 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@inga-lovinde
Copy link

inga-lovinde commented Apr 3, 2020

TypeScript Version: 3.8.3

Search Terms:

  • type Exclude keyof is not assignable to type Exclude Exclude keyof
  • exclude idempotent

Code

const f = <T>(arg: Omit<T, 'field'>) => {
    const a = { ...arg, field: 'value' };
    const { field, ...b } = a;
    const c: Omit<T, 'field'> = a;
    const d: Omit<T, 'field'> = b;
    return { c, d };
};

Expected behavior:
Code compiles.

Actual behavior:
Compilation error on d initialization (but not on c initialization):

tmp.ts:5:11 - error TS2322: Type 'Pick<Pick<T, Exclude<keyof T, "field">> & { field: string; }, Exclude<Exclude<keyof T, "field">, "field">>' is not assignable to type 'Pick<T, Exclude<keyof T, "field">>'.
  Type 'Exclude<keyof T, "field">' is not assignable to type 'Exclude<Exclude<keyof T, "field">, "field">'.
    Type 'keyof T' is not assignable to type 'Exclude<keyof T, "field">'.

5     const d: Omit<T, 'field'> = b;
            ~


Found 1 error.

Playground Link: Playground Link

Related Issues: I did not find other related issues.

@inga-lovinde inga-lovinde changed the title Exclude<Exclude<keyof T, 'x'>, 'x'> should be assignable to Exclude<keyof T, 'x'> Exclude<keyof T, 'x'> should be assignable to Exclude<Exclude<keyof T, 'x'>, 'x'> Apr 3, 2020
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 22, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants