Open
Description
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.