Closed
Description
Edit: keyof
works as I thought; mapped types are just broken in interfaces. I also clarified a few things.
Allowing negated types and F-bounded mapped type variables would solve several issues:
- Subtraction types: Subtraction types #4183 - The proposed
A - B
could be encoded asA & !B
as per this proposal. - Mapped conditional types: Mapped conditional types #12424 - For key-based conditions, this + F-bounded mapped types would allow that to be solved without explicit support.
- Promises - Having negated types makes it possible to prevent thenables from being used as generic Promise parameters.
Here's my proposal:
-
Allow negated types, using
!T
to represent the set of all types that do not conform toT
(i.e. not assignable toT
). This is pretty simple to digest. -
Expand mapped types to allow the key variable to be F-bounded, like in
{[P in Keys<T, P>]: ...}
.
The first is sufficient to cover subtraction types and Promise type issues, and the other two make mapped conditional types possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment