fix(transformer/legacy-decorator): simplify enum type inference#13357
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #13357 will not alter performanceComparing Summary
|
523a349 to
ed7a60c
Compare
~x|
@Dunqing I'm not completely sure about this. I think it's OK to ignore PS: Sorry, it was me that said we needed to check the |
Correct! If they can't pass the type checker, then we can't ensure that we will infer the correct type. |
Merge activity
|
Follow-on after #13327. It seems that TS infers the type of `+x`, `-x`, and `~x` as `Number`, no matter what `x` is. All other `UnaryOperator`s (`!x`, `void x`, `typeof x`, `delete x`) are illegal as enum initializers, so we can ignore those cases and just say all `UnaryExpression`s are `Number`s. [TS Playground](https://www.typescriptlang.org/play/?experimentalDecorators=true&emitDecoratorMetadata=true&target=99#code/GYVwdgxgLglg9mABAcwKZQMpQE4zMgCgEpEBvRbdEbJAcgGcc9laBuRAXwCgvUwQAtogCqYAIbYAngHkoAC1TYAovyGkuiRGFTIxsAG6pEAXkQBaNJib5iAGg2IADnHowDR0wGpLWXDaL2mgBGbgDuMPQeiAB+PtaEAVzcXKCQsAiIACaoEHDYeqgEAPpQEpYAXIhiYJK2iEWO2HCOilCSlYx+yCSkyagAHs7YUIgQADZi9PSIAGJwcGQOAALZuflQqA7gEjLyigAKTY6VojuyCsqqJiLiUueKKoIAdNq67qxJXEA) Additionally, `BigInt`s are illegal as enum initializers, so we can ignore them too. [TS Playground](https://www.typescriptlang.org/play/?experimentalDecorators=true&emitDecoratorMetadata=true&target=99#code/KYOwrgtgBAQglgcwJIgC4FFzQN4CgpQBGiUAvFAIwAMVIANPkYgsAE5mU0324C+uQA) We can therefore simplify type inference for decorators.
ed7a60c to
5a25c06
Compare

Follow-on after #13327.
It seems that TS infers the type of
+x,-x, and~xasNumber, no matter whatxis.All other
UnaryOperators (!x,void x,typeof x,delete x) are illegal as enum initializers, so we can ignore those cases and just say allUnaryExpressions areNumbers.TS Playground
Additionally,
BigInts are illegal as enum initializers, so we can ignore them too.TS Playground
We can therefore simplify type inference for decorators.