Skip to content

Design Meeting Notes, 6/8/2018 #24801

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 Jun 8, 2018 · 1 comment
Closed

Design Meeting Notes, 6/8/2018 #24801

DanielRosenwasser opened this issue Jun 8, 2018 · 1 comment
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

defaultProps and propTypes

#23812

  • LibraryManagedAttributes
    • Basically a type alias that infers from the component and creates the external prop
  • This proposal tackles both defaultProps and propTypes
    • But really it's two different things.
    • The "common" thing is to defaultProps
  • This implementation doesn't actually do any specific checking on propTypes and defaultTypes
  • Currently the suggested implementation for LibraryManagedAttributes says "anything in the types of defaultTypes makes things optional"
    • This gives you undesirable behavior for people who have written static defaultTypes: Partial<MyProps> ...
  • What do the error messages look like?
    • Bad.
    • But no worse than JSX error messages today.
      • Not a good thing.
    • We're working on this anyway.
  • Action item: find some real world code with propTypes.
  • Need strong guidance.

Parameter list capture and variadic functions

  • One of the primary ideas is "can I please capture an argument list as a tuple?"

    • So I don't have to write overloads over and over for respective functions.
  • Built-ins are untyped like call, bind, apply are untyped.

  • Someone asked "can't we just capture rest parameter generics as tuples?"

    function baz<T extends unknown[]>(...args: T): T {
        throw "nope";
    }
    
    baz("foo", 100); // [string, number]
  • Action item:

    baz<"foo">("bar"); // infers as 'string' - why?
  • Can now type things like curry.

    declare function curry<T, U extends unknown[], R>(f: (x: T, ...rest: U) => R, x: T):
        (...args: U) => R;
  • To make this work, we need tuples to be able to encode anything in a parameter list.

    • need optionality: ?
    • and open-endedness: ...
  • Have added optionality: `[Foo, Bar?, Baz]

    • But this means you can never use ? as a postfix type syntax.
      • Well just right there!
      • But we're probably never going to use that syntax.
  • Can finally write a Parameters helper type.

    type Parameters<T extends (...args: any[]) => any> =
      T extends (...args: infer U) => any ? U : never;
  • How does this work with Promises?

    • It doesn't!
    • Well make this work well with things like promisify?
    • Or JSX
  • Overall this is a big improvement with little added complexity.

    • And more general variadic constructs seem to follow from this.
  • But hey, we're already pretty powerful with this feature!

    type TupleTail<T extends any[]> =
      ((...args: T) => void) extends ((head: any, ...tail: infer U) => void) ?
          U : never;
  • Is this a breaking change to func.call?

    • Yes because
      • it's sometimes more accurate
      • we don't handle overloads
  • Run it on RWC and DefinitelyTyped.

  • What do errors look like?

    • Not so bad.
    • But there is the problem where you lose parameter list names.
    • Could capture them in inference?
    • Does this lead to named tuples?
      • ...maybe!
@DanielRosenwasser DanielRosenwasser added the Design Notes Notes from our design meetings label Jun 8, 2018
@mhegazy mhegazy closed this as completed Jun 8, 2018
@Kingwl
Copy link
Contributor

Kingwl commented Jun 8, 2018

But hey, we're already pretty powerful with this feature!

type TupleTail<T extends any[]> =
  ((...args: T) => void) extends ((head: any, ...tail: infer U) => void) ?
      U : never;

The syntax looks complicated and there are too many symbols

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

3 participants