Skip to content

fix(transformer/legacy-decorator): simplify enum type inference#13357

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_
Aug 29, 2025
Merged

fix(transformer/legacy-decorator): simplify enum type inference#13357
graphite-app[bot] merged 1 commit intomainfrom
08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 28, 2025

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 UnaryOperators (!x, void x, typeof x, delete x) are illegal as enum initializers, so we can ignore those cases and just say all UnaryExpressions are Numbers.

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.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Aug 28, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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-hq
Copy link

codspeed-hq bot commented Aug 28, 2025

CodSpeed Instrumentation Performance Report

Merging #13357 will not alter performance

Comparing 08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_ (5a25c06) with main (3065e13)

Summary

✅ 38 untouched benchmarks

@overlookmotel overlookmotel force-pushed the 08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_ branch from 523a349 to ed7a60c Compare August 28, 2025 17:34
@overlookmotel overlookmotel marked this pull request as ready for review August 28, 2025 17:40
@overlookmotel overlookmotel requested a review from Dunqing as a code owner August 28, 2025 17:40
@overlookmotel overlookmotel changed the title fix(transformer/legacy-decorator): infer type of nested unary expressions and ~x fix(transformer/legacy-decorator): simplify enum type inference Aug 28, 2025
@overlookmotel
Copy link
Member Author

overlookmotel commented Aug 28, 2025

@Dunqing I'm not completely sure about this. I think it's OK to ignore BigInt and other illegal patterns, since in code which passes the type checker, they can't happen. But is that the right approach?

PS: Sorry, it was me that said we needed to check the UnaryOperator in the first place, and now I'm saying we don't!

@Dunqing
Copy link
Member

Dunqing commented Aug 29, 2025

@Dunqing I'm not completely sure about this. I think it's OK to ignore BigInt and other illegal patterns, since in code which passes the type checker, they can't happen. But is that the right approach?

PS: Sorry, it was me that said we needed to check the UnaryOperator in the first place, and now I'm saying we don't!

Correct! If they can't pass the type checker, then we can't ensure that we will infer the correct type.

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Aug 29, 2025
Copy link
Member

Dunqing commented Aug 29, 2025

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.
@graphite-app graphite-app bot force-pushed the 08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_ branch from ed7a60c to 5a25c06 Compare August 29, 2025 04:56
Copilot AI review requested due to automatic review settings August 29, 2025 04:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@graphite-app graphite-app bot merged commit 5a25c06 into main Aug 29, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 08-28-fix_transformer_legacy-decorator_infer_type_of_nested_unary_expressions_and_x_ branch August 29, 2025 05:01
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants