Skip to content
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

Design Meeting Notes, 1/29/2020 #42590

Closed
DanielRosenwasser opened this issue Feb 1, 2021 · 0 comments
Closed

Design Meeting Notes, 1/29/2020 #42590

DanielRosenwasser opened this issue Feb 1, 2021 · 0 comments
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

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.

@DanielRosenwasser DanielRosenwasser added the Design Notes Notes from our design meetings label Feb 1, 2021
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