Skip to content
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

Allow negated types + F-bounded mapped types #18280

Closed
dead-claudia opened this issue Sep 6, 2017 · 5 comments
Closed

Allow negated types + F-bounded mapped types #18280

dead-claudia opened this issue Sep 6, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@dead-claudia
Copy link

dead-claudia commented Sep 6, 2017

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:

Here's my proposal:

  1. 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.

  2. 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.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented 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
Copy link
Author

@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.

@dead-claudia dead-claudia changed the title Allow negated types + expand keyof to accept any type Allow negated types + F-bounded mapped types Sep 7, 2017
@SalathielGenese
Copy link

I upvote A & !B especially the !B part... Over Exclude from #21847

@mhegazy
Copy link
Contributor

mhegazy commented 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.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 9, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants