GeezerVison is showing github.com — Allow negated types + F-bounded mapped types · Issue #18280 · microsoft/TypeScript
Allow negated types + F-bounded mapped types #18280DescriptionEdit: 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:
Here's my proposal:
-
Allow negated types, using !T to represent the set of all types that do not conform to T (i.e. not assignable to T). 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. Reacted by Joe Calzaretta, Alex, Shai Reznik, Andrey Godyaev, Stephen Laughton, Alexis Fontaine and Troy Gerwien Reacted by Aluan Haddad, ezequiel-umu, Remo H. Jansen, Sean M. Vieira and Stephen Laughton Activityaluanhaddad commented on Sep 6, 2017 Big 👍 on the proposed syntax. I think the negation operator is indeed quite intuitive in the context of mapped types/keyof and is a great idea. My only concern is that I'm not sure what it means outside of an intersection context. "Does not conform to T" could be construed as meaning not assignable to T which is very different from meaning not having any of the keys of T. This may just need further clarification.
Minor nitpick, but I believe your second item is already valid today. dead-claudia commented on Sep 7, 2017 Aluan Haddad (@aluanhaddad)
My only concern is that I'm not sure what it means outside of an intersection context.
This comment should explain type negation outside a union context (partial Promise fix).
"Does not conform to T" could be construed as meaning not assignable to T which is very different from meaning not having any of the keys of T.
"not assignable to T" is actually the intended meaning for negated types. This happens to be equivalent to "not having any of the keys of T" in the context of object types, but it carries more expected semantics for primitives.
Minor nitpick, but I believe your second item is already valid today.
Yeah...I figured this out; I just ran into this odd bug. changed the title [-]Allow negated types + expand `keyof` to accept any type[/-] [+]Allow negated types + F-bounded mapped types[/+] on Sep 7, 2017SalathielGenese commented on Mar 9, 2018 I upvote A & !B especially the !B part... Over Exclude from #21847 mhegazy commented on Mar 9, 2018 Looks like the same feature as #4196, just different proposal. i suggests adding the proposal to #4196 and keeping the discussion to one issue. typescript-bot commented on Mar 23, 2018 Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|