GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow negated types + F-bounded mapped types · Issue #18280 · microsoft/TypeScript

Allow negated types + F-bounded mapped types #18280

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow negated types + F-bounded mapped types#18280
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created

Description

@dead-claudia
Claudia Meadows (dead-claudia)
opened on Sep 6, 2017
Issue body actions

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 as A & !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:

  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.

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

Activity

  1. aluanhaddad commented on Sep 6, 2017

    @aluanhaddad
    Aluan Haddad (aluanhaddad)
    on Sep 6, 2017
    Contributor
    More actions

    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.

  2. dead-claudia commented on Sep 7, 2017

    @dead-claudia
    Claudia Meadows (dead-claudia)
    on Sep 7, 2017
    Author
    More actions

    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.

  3. Claudia Meadows (dead-claudia)
    changed the title [-]Allow negated types + expand `keyof` to accept any type[/-] [+]Allow negated types + F-bounded mapped types[/+] on Sep 7, 2017
  4. SalathielGenese commented on Mar 9, 2018

    @SalathielGenese
    Salathiel Genese (SalathielGenese)
    on Mar 9, 2018
    More actions

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

  5. mhegazy commented on Mar 9, 2018

    @mhegazy
    Mohamed Hegazy (mhegazy)
    on Mar 9, 2018
    Contributor
    More actions

    Looks like the same feature as #4196, just different proposal. i suggests adding the proposal to #4196 and keeping the discussion to one issue.

  6. Mohamed Hegazy (mhegazy)
    added
    DuplicateAn existing issue was already createdAn existing issue was already created
    on Mar 9, 2018
  7. typescript-bot commented on Mar 23, 2018

    @typescript-bot
    TypeScript Bot (typescript-bot)
    on Mar 23, 2018
    Contributor
    More actions

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

  8. TypeScript Bot (typescript-bot)
    closed this as completedon Mar 23, 2018
  9. microsoft
    locked and limited conversation to collaborators on Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.