-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Description
TypeScript Version: 3.6.0
Search Terms:
Omit
Omit any
Code
interface Foo {
a: string;
b: number;
c: boolean
}
// Omit has the issue
type FooWithoutC = Omit<Foo, "c">; // no intellisense for second generic parameter
type FooWithoutD = Omit<Foo, "d">; // no type error
// Counter example with Pick
type FooWithA = Pick<Foo, "a">; // provides intellisense for filling out second generic parameter
type FooWithD = Pick<Foo, "d">; // type error
Expected behavior:
In the above example, I would expect
- to get auto-completion for keys of
Foo
when filling out the second generic parameter - to get a type error when putting in a key that does not exist on
Foo
similar to how it works in all the other similar helpers, e.g. Pick
.
Actual behavior:
Since the definition of the second generic parameter is keyof any
instead of keyof T
, I can put whatever I want into the second generic parameter, and I also get no Intellisense.
Related line:
Line 1449 in ea73093
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>; |
Is there a reason why this has been implemented like this with keyof any
instead of keyof T
?
Activity
gins3000 commentedon Jul 12, 2019
Never mind, apparently there is already an issue about this: #30825