Description
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
-
Eliminate well known symbols as a concept in the checker and rely on unique symbols #42543
-
Expunge the concept of well-known symbols from the checker #24738
-
Came up again with Expunge the concept of well-known symbols from the checker #24738 (comment)
-
Seems to help bring us to where we'd have wanted to be if we had unique symbol 5 years ago.
-
Seems like we only didn't bring this in because other work came up (e.g. lib references)
-
unique symbol
is no panacea, nominal results.- Seems like nominality is not a problem here.
-
keyof
works now too which is neat! -
Symbol.for
is one last place whereunique symbol
still causes issues. -
Conclusion: drive for 4.3.
Bitflag Enums and Non-Union Enums
-
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.