-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Design NotesNotes from our design meetingsNotes from our design meetings
Description
Template Types and Key Remapping
Template Types and infer
- Lots of cool stuff people have built with it.
- Also lots of... uhhhhh.
- Inference is what makes this feature so powerful
- Could match against known delimiters.
- Got a lot of feedback that it was hard to get a single character.
- Changed things so that by default, inference positions always try to grab one character from the string.
- What's the definition of a "character"?
- 16-bit codepoint - whatever you get from
charAt. Not necessarily well-formed.- Is that good?
- Not clear.
- Changed things so that by default, inference positions always try to grab one character from the string.
- Is it worth noting that CSS's
text-transformvalues distinguish betweencapitalizeanduppercase?- The former uppercases the first letter of each word; the latter uppercases every letter.
- That's how this feature works.
- Sounds like we're adding another "secret feature" like wrapping your types in
[]in conditional types to avoid distributivity. - Iterating over characters is a useful thing, but is this the right way to do things.
- One thing we could say is that you write
`${...infer Foo}`to get all potential arrays of characters inFoo
- One thing we could say is that you write
- Is a reasonable desugaring the
inferwith delimiterD=(.*?D)- Looks like yes.
inferwith no delimiter =(.?)- No! You must always consume, will never match the empty string.
- Inference will fail in cases where you have no contents to infer from.
inferwith no delimiter =(.)
- No! You must always consume, will never match the empty string.
- Is there a way to make it optional so that it's "infer a character if you can"? i.e.
(.?)- Unclear.
- [[Example of loop-unrolling to defeat the depth limiter.]]
- Editor's note: this delights me.
- What is the difference between intended use and out of scope with this feature?
- Very hazy, can't do this without measuring "units of work".
- Need some sort of way to debug the program in the type system now.
- printf types?
- throw types (Throw types #40402)?
as clauses
- Adding an
asclause removes the constraint of the type being iterated over - so in{ [K in T as Foo]: Bar }, there is no constraint onTat all!
Future Direction
- Today,
`a${"b"}` as constisstring - Can imagine making it
"ab". - But what about
`a${x}` as constbeing`a${typeof x}`? - Can't do it for every position - it would be a breaking change.
- But could do it with
as const- kind of a signal to "constant fold" the types.
- But could do it with
Metadata
Metadata
Assignees
Labels
Design NotesNotes from our design meetingsNotes from our design meetings