Skip to content

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

@inga-lovinde

Description

@inga-lovinde

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions