Skip to content

Design Meeting Notes, 10/18/2019 #34576

@DanielRosenwasser

Description

@DanielRosenwasser

TC39 Updates

  • TC39 update
    • globalThis to stage 4
    • New in stage 3: Promise.any, String#replaceAll, formalized for-in object iteration
    • New in stage 2: Map#upsert
    • New in stage 1: A bunch of stuff
      • Readonly collections
      • Records and tuples #{ x: 0 }

Optional Chaining and Narrowing

#33736

  • Have been iterating on feedback around narrowing optional chaining.

  • type Header = { headers: Record<string, any> };
    type Options = { config : any };
    
    function getHeader(input: Header | Options,   key: string, def?: any) {
       return ('headers' in input ? input.headers  [key] : undefined) || def;
    }
  • Today, in adds a property to the original type.

  • type Header = { headers: Record<string, any> };
    type Options = { config: any };
    
    function getHeader(input: Header | Options,   key: string, def?: any) {
       return input.headers?.[key] ?? def;
    }
  • Uhh.

Correcting Loose Assignability Rules for Intersections to Index Signatures

#32484

declare let s: { a: string } & { b: string };
declare let t: { [key: string]: string };
t = s;
  • Our assignability rules say that if any constituent of an intersection is assignable to an index signature, the types are assignable.
    • UHH.
  • Happens when you work on dictionary-like objects.
  • We don't have a concrete rule yet, but have been observing some pain.
  • Technically even { a: string } being assignable to Record<string, string> is wrong because { a: string } can contain more properties than it declares.
    • Otherwise it would be extremely difficult to deal with dictionary-like bags of properties.
  • Probably 3.8-bound at earliest.

devDependencies in @types Packages

microsoft/types-publisher#655

  • Problem: today, an app can't have both @types/node and @types/react-native in the same dependency tree.
    • This is because they both define globals.
  • Solution 1: "Just let them coincide"?
  • Solution 2: Give a blessed configuration for web and for react native?
  • Solution 3: Be careful about the @types in your dependency trees.
  • But then other problems...
  • Problem: a library that wraps both react and react-native components can't have a dependency on either!
  • The whole situation is a mess: react depends on react-dom, react-native depends on react, some of these APIs use Buffers when you're in Node.
  • What about a forward-declaration mechanism?
  • Are there libraries with these problems in DefinitelyTyped otherwise?
    • Yes!
  • With Placeholder Type Declarations #31894, is the idea that you just say "there's a Buffer"?
    • Yes, "don't care what it is, but I'll take one!"
  • Anything else you can't do with interfaces instead of forward declarations?
    • Well you can't forward-declare a type alias to a union type or tuple.
    • IteratorResult ended up with this issue, meant we needed to do typesVersions.
  • What happened last time we chatted about placeholder types?
    • Tried to see if we could break the feature down into different functionality.
  • What about conditional inclusion?
    • Something like type polyfills?
    • Swift potentially has something like this.
    • But how do you explore versioning?
  • Feels like this has turned into a discussion about many different problems.
    • Original problem: devDependency to check on DefinitelyTyped, let users install the correct peer types.
  • Does this stand up to other future solutions?
    • Unclear if this paints us into a corner.
    • How do you tell users "you have to also install @types/node now"?
  • Also, there's an excludeTypes (Placeholder Type Declarations #31894) - a way to say "no, please don't add @types/node from being included".
    • But someone asked for those types to be included indirectly.
  • Aside: .NET has had this problem since...forever and solved it with...not working correctly? :(
  • What if @types packages could fulfull lib settings, and then we could provide lib?
  • Conclusion: We will scope down and isolate the concerns in a separate meeting.
    • Also, of all the types that rely on @types/node, what do they rely on?

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