Skip to content

Not possible to use const string as enum valueΒ #61064

Closed as not planned
Closed as not planned

Description

πŸ”Ž 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

Activity

  1. MartinJohns commented on Jan 28, 2025

    @MartinJohns
    Contributor

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

  2. typescript-bot commented on Jan 31, 2025

    @typescript-bot
    Contributor

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

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions