Skip to content

Conversation

@paulmand3l
Copy link
Contributor

@paulmand3l paulmand3l commented Oct 28, 2025

Addresses #1222

Currently, if we try to generate typescript with the option removeEnumPrefix enabled and encounter and enum like:

enum Option {
  OPTION_1 = 0;
  OPTION_2 = 1;
}

We strip the enum name prefix and generate invalid typescript:

enum Option {
  1,
  2,
}

This changes this behavior to strip the enum prefix only if all resulting values are valid, advisable typescript. E.g.

enum Option {
  OPTION_1 = 0;
  OPTION_FOO = 1;
}

Becomes

enum Option {
  OPTION_1,
  OPTION_FOO,
}

This will treat as numeric:

  • Any combination of pure numbers (e.g. OPTION_001010362)
  • Any string with a number first (e.g. OPTION_1A)
  • Infinity (e.g. OPTION_INFINITY) - note that this results in a technically valid typescript enum but seems like it will cause problems elsewhere.

@paulmand3l paulmand3l changed the title Keep enum prefix if would be numeric without (fix) Keep enum prefix if would be numeric without Oct 28, 2025
@paulmand3l paulmand3l changed the title (fix) Keep enum prefix if would be numeric without fix - Keep enum prefix if would be numeric without Oct 28, 2025
@paulmand3l paulmand3l changed the title fix - Keep enum prefix if would be numeric without fix: Keep enum prefix if would be numeric without Oct 28, 2025
Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

Looks great @paulmand3l , thank you!

@stephenh stephenh merged commit a6bad92 into stephenh:main Oct 29, 2025
6 checks passed
stephenh pushed a commit that referenced this pull request Oct 29, 2025
## [2.8.2](v2.8.1...v2.8.2) (2025-10-29)

### Bug Fixes

* Keep enum prefix if would be numeric without ([#1223](#1223)) ([a6bad92](a6bad92))
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 2.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants