Skip to content

Not possible to use const string as enum value #61064

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

Closed
Friend-LGA opened this issue Jan 28, 2025 · 2 comments
Closed

Not possible to use const string as enum value #61064

Friend-LGA opened this issue Jan 28, 2025 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Friend-LGA
Copy link

πŸ”Ž Search Terms

enum const string computed value 18033

πŸ•— Version & Regression Information

I tried 2 TS versions, reproducible with both:

  • 5.6.2
  • 5.7.3

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCAOUCW4BMMC8MDkDluwG4AoUSWPFMAZkx0vGuxgEMIYzoTiBTAD3ggATrB5gArgFsYAFR7QAohOkBvYjBgB5RFQCMdXDvC7sAGnVajYdFgbXTMAPSOYAHncwwIGDyFDh7AAWvjwW2vg0dHbUDs5uHlAQABS6ABwADNTUAJQ+fsIwwUKhAL5AA

πŸ’» Code

const option2 = 'option2';
const option3 = 'option3' as const;

export enum TestEnum {
  Option1 = 'option1',
  Option2 = option2, // <<< no errors here
  Option3 = option3, // <<< ts(18033) error here
}

πŸ™ Actual behavior

Blocked by ts(18033) error

πŸ™‚ Expected behavior

No ts(18033) error

Additional information about the issue

When string variable created as const it's impossible to use it as an enum value because of ts(18033) error.
As far as I'm aware this behaviour should've been implemented as part of this issue #40793

@MartinJohns
Copy link
Contributor

MartinJohns commented Jan 28, 2025

Duplicate of #59346. The related PR has not been merged yet: #59475

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 28, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants