Skip to content

Design Meeting Notes, 1/29/2020 #42590

Closed
Closed
@DanielRosenwasser

Description

@DanielRosenwasser

Big arrays of discriminated unions

let x: Action[] = [
    { type: 1, payload 42 },
    { type: 2, payload 42 },
    { type: 3, payload 42 },
    // ...
];
  • Linear search on every element to see if it matches a type in Action.
    • O(n * m), n = number of elements, m = number of union constituents
    • Also, structural comparison on each element.
  • A couple of places where we can optimize on these cases.
  • In an array literal, if we have a contextual type (and we're not in a inference-checking mode), no reason to perform subtyping.
    • We generally try to report element-wise on constituents of an array - but in cases where we can't, you might end up with a bigger union.
  • When the target side is a discriminated union, we can try to map to the right types and compare against those.
    • Could reuse the same logic for contextual typing by discriminated unions.

Consider Well-Known Symbols To Be unique

Bitflag Enums and Non-Union Enums

  • Modifier for bitflag enums #42521

  • Add 'bitflags' modifier for enum. #42533

  • Not opposed to adding a restriction of some sort - but opposed to adding a keyword.

    • enum is a reserved word for JS, want to make sure that we're not going in an incompatible direction.
    • Comment-like modifier could work.
  • Funny thing about the PR is that we already have union enums and "classic" enums.

    • Union enums introduce a union of different individual member types.
    • You get these enums when you write no initializer for you values.
    • We have a rule that says that number is not assignable to any union enum types.
  • Today you have to be careful because writing anything other than a literal expression throws you out of union enum land.

  • Returning to syntax, opportunity to find syntax after name, before brace.

    • Still wary of any syntax because ES could use it.
  • Just want a way to disable bit-flagginess/numeric behavior.

  • Don't necessarily want to take this PR, should consider a "strict enum mode".

    • Also, even if we wanted to take it, we couldn't/shouldn't because of the syntax concern.
  • More thought needed.

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