TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Omit Type

Open mamadshni opened this issue 10 months ago • 1 comments

In the definition of Omit, we have: type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

However, I assume this definition is incorrect because we are trying to exclude some keys (K) from the type (T), but K is defined as K extends keyof any. I believe it should be K extends keyof T instead, so that we only allow keys from T to be excluded from T.

🙁 Actual behavior

type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

🙂 Expected behavior

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

mamadshni avatar Mar 12 '25 11:03 mamadshni

This is working as intended: https://github.com/microsoft/typescript/wiki/faq#add-a-key-constraint-to-omit

MartinJohns avatar Mar 12 '25 11:03 MartinJohns

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

typescript-bot avatar Mar 17 '25 01:03 typescript-bot