I could make great use of a type like Extract<T>
that would resolve to all the types in a union T
that are NOT string
or number
. Is this possible?
Extract<T, string | number>
will find everything that extends string
or number
, but I want something that will extract everything this is not exactly string
or number
.
Some examples of what I want, if the type was named NonIndex
:
NonIndex<string | 1>; // expect 1
NonIndex<'a' | 1>; // expect 'a' | 1
NonIndex<string | 'a'>; // expect 'a'
Here is the closest I've come in the playground, but you can see it's not right yet. Can it be done?
My motivating use case is to (substantially) improve the typing of omit()
in one of my open source libraries. If you're very brave, you can take a look at my almost solution here. But beware, it has a lot of typing going on! Everything is working well except the last line, as commented at that link.