Skip to content

Design Meeting Notes, 9/8/2020 #40504

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

Closed
DanielRosenwasser opened this issue Sep 11, 2020 · 0 comments
Closed

Design Meeting Notes, 9/8/2020 #40504

DanielRosenwasser opened this issue Sep 11, 2020 · 0 comments
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

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.
    • Is it worth noting that CSS's text-transform values distinguish between capitalize and uppercase?
      • 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 in Foo
    • Is a reasonable desugaring the
      • infer with delimiter D = (.*?D)
        • Looks like yes.
      • infer with 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.
        • infer with no delimiter = (.)
  • 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.

as clauses

  • Adding an as clause removes the constraint of the type being iterated over - so in { [K in T as Foo]: Bar }, there is no constraint on T at all!

Future Direction

  • Today, `a${"b"}` as const is string
  • Can imagine making it "ab".
  • But what about `a${x}` as const being `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.
@DanielRosenwasser DanielRosenwasser added the Design Notes Notes from our design meetings label Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Notes Notes from our design meetings
Projects
None yet
Development

No branches or pull requests

1 participant