-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Omit
returns an invalid type when the target has a generic key
#45177
Comments
This comment has been minimized.
This comment has been minimized.
Duplicate of #43139 and others |
This is extremely counterintuitive. |
It's due to the design of the language, and there are workaround available. |
I've updated the example. |
I'm sure there are, but I don't want to write long lines like this OmitIndex<OmitIndex<OmitIndex<Example, 'foo'>, 'bar'>, 'baz'> |
There is no mention of a |
See #41966 type EqualsTest<T> = <A>() => A extends T ? 1 : 0;
type Equals<A1, A2> = EqualsTest<A2> extends EqualsTest<A1> ? 1 : 0;
type Filter<K, I> = Equals<K, I> extends 1 ? never : K;
type OmitIndex<T, I extends string | number> = {
[K in keyof T as Filter<K, I>]: T[K];
}; |
Figured it out. I just need to fix the type Filter<K, I> = Equals<K, I> extends 1 ? never : IfPrimitiveString<I, K, (K extends I ? never : K)>;
// or (which I prefer)
type Filter<K, I> = IfPrimitiveString<I, Equals<K, I> extends 1 ? never : K, K extends I ? never : K>; |
Bug Report
🔎 Search Terms
omit generic
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
test.foo
isunknown
🙂 Expected behavior
test.foo
should benumber
The text was updated successfully, but these errors were encountered: