Closed
Description
Key Mapping in Mapped Types
-
"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"]
- Thanks to recursive conditionals, you can now (cleanly) write a
-
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"
.
- This is currently already possible when you have the numeric key
- Map to
-
Operators: uppercase, lowercase, capitalize, uncapitalize
- Locale?
- Locale-neutral (?)
- Eventually, people will want to go to/from kebab-case, camelCase, snake_case, etc.
- Locale?
-
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't do
-
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 thein
)- Most other people on the team seem okay with it.
customDescriptionGenerator
- This is more about infrastructure for our team when debugging in VS Code.
- Ways to have nodes display a certain way in debuggers.
- Can add more information to
Node
s,Symbol
s,Signature
s,FlowNode
s. - Currently available through https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug-nightly