Skip to content

Design Meeting Notes, 2/12/2016 #7059

Closed
@RyanCavanaugh

Description

@RyanCavanaugh
  • Implicit Index Signatures Implicit index signatures #7029
    • issue Why does { foo: T } not satisfy { [key:string]: T }? #6041 and many others logged in the past
    • Longstanding pain point / confusion source
    • Bad solution you might think of: Infer this all the time
      • Very bad -- passing string to Map<T> infers insane type for T, for example
    • Now infer index signatures during assignability in certain cases
      • Allowed for types inferred from object literals and object type literals, which do not have call/construct signatures
        • Object type literals because .d.ts files
    • Now we don't need to contextually type in index signatures
      • Error message quality improves
      • We can identify the violating member of an object type
    • Q: What's the difference between an interface and an object literal type?
      • Interface types are always explicit
      • No one is complaining about that (yet?)
      • Main problem seems to be in object literals
    • Concern: Switching from type alias to interface is going to have behavioral differences
      • We could include interfaces, but it's a trade-off with detecting errors
    • Q: What are the other differences between object literal types and interfaces?
      • You can inherit from an interface
      • Display (name vs anonymous type)
      • Concern: This breaks an existing symmetry
    • Could we just infer a string indexer for all object literals?
      • This would cause a lot of error noise
      • Plus type allocation
    • Q: What happens to type queries of these object literals? Are they still object literal types?
      • Yes, same type
    • Concern: Symmetry of declaration file vs implementation file, vs symmetry of object type literal vs interface type
      • e.g. What if we wrote the index signature into the .d.ts file during generation?
    • Note that this index signature isn't actually present -- indexing the object by a string is still an implicit any
    • What about only inferring the index signature when all properties have the same type?
      • Not useful, consider { x: HTMLSpanElement, y: HTMLDivElement }
    • 👍
  • Constructor Visibility Constructor Visibility #6885
    • Issue Allow visibility on constructors #4174
    • What are the exact assignability / visibility rules?
      • As written
    • Add testcases for class expressions in the PR
    • TODO: Log issue that class expressions inside classes can refer to their enclosing class's privates / protecteds
    • It should be legal to extend a private constructor from within a class expression inside that same class
    • Otherwise good to go
  • Type acquisition
    • TL;DR version
      1. We can't fix this until people write their .d.ts files as true modules
      2. But we have to because people haven't
      3. But we can't
      4. But we have to
      5. But we can't
      6. But we have to
    • We need to solve the problem of why people are writing .d.ts file as globally-declared external modules
      • Because global type augmentation was impossible
      • Because augmentation of other types was hard
      • Because UMD pattern
      • Because you don't want 200 .d.ts files if you have 200 modules
        • Can we fake this as long as there are no global declarations?
    • Consequentialism vs Platonic ideals
    • Is versioning conflict a real thing?
      • Badness of problem vs commonness of occurence
      • When will this happen?

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