Skip to content

Design Meeting Notes, 8/28/2020 #40309

Closed
Closed
@DanielRosenwasser

Description

@DanielRosenwasser

Key Mapping in Mapped Types

#12754

  • "Key mapping" is really 3 features:

    • String concatenation types
    • A name clause for keys in mapped types
    • 4 new type operators - haven't done these
  • String concat types

    • Thanks to recursive conditionals, you can now (cleanly) write a Join operator that takes a bunch of literals and separates them by a delimiter.
      • Join<["a", "b", "c"], "," -> "a,b,c"
      • You can write Split using inference; string splitting uses non-greedy matching.
        • Split<"a,b,c", ","> -> ["a", "b", "c"]
  • Name clause for mapped types

    type Foo<T> = { [K in keyof T as `get_${K}` ]: () => T[K] };
    //                            ^^^^^^^^^^^^^
    // Current syntax
    • Naming breaks the special-casing for array-like types where it just maps over the indexes.
    • Interestingly, you can map to more or fewer keys in these clauses!
      • Map to never, and that removes a key
      • Map to multiple keys, and they'll all have the same type.
      • When multiple mapped keys overlap at any point, and they'll be unioned.
        I * Have to make sure that's the behavior (bug in current implementation)
        • This is currently already possible when you have the numeric key 0 and the string key "0".
  • Operators: uppercase, lowercase, capitalize, uncapitalize

    • Locale?
      • Locale-neutral (?)
    • Eventually, people will want to go to/from kebab-case, camelCase, snake_case, etc.
  • Previously had an error on large unions.

    • 100K constituents.
    • Had to enforce the same for string concatentation and spreads.
      • Can't do `${Digit}${Digit}${Digit}${Digit}${Digit}`
  • Can imagine a prefix in these strings the same way find/replace works in editors

    • \u${SomeType}
    • But conflicts with strings
    • We like how we're not conflating the operations with the strings
    • Also, like [[something from C# - @rbuckton fill this in]].
  • How do we feel about as in key mapping?

    • as looks like it is doing something with the constraint of the mapped type (the right side of the in)
    • Most other people on the team seem okay with it.

customDescriptionGenerator

https://github.com/microsoft/vscode-js-debug/blob/a04cff2e4c2b39616d4e1b813f41a40643b9fa76/OPTIONS.md#customdescriptiongenerator-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design NotesNotes from our design meetings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions