Skip to content
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

Allow satisfies in string enum member initializers #60060

Open
6 tasks done
bgenia opened this issue Sep 25, 2024 · 0 comments
Open
6 tasks done

Allow satisfies in string enum member initializers #60060

bgenia opened this issue Sep 25, 2024 · 0 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@bgenia
Copy link

bgenia commented Sep 25, 2024

πŸ” Search Terms

satisfies, enum

βœ… Viability Checklist

⭐ Suggestion

I suggest that TypeScript should allow this:

enum Foo {
  Foo = "Foo" satisfies "Foo"
}

Currently this is treated as a computed enum member and requires number type, despite nothing being actually computed here.

πŸ“ƒ Motivating Example

With isolatedModules/isolatedDeclarations enabled references in enum members are restricted. For example, this does not compile with isolatedDeclarations:

const FOO = "Foo"

enum Foo { Foo = FOO }
// Error: Enum member initializers must be computable without references to external symbols with --isolatedDeclarations.

satisfies here will ensure that Foo is properly typed while not referring to external symbols:

const FOO = "Foo"

enum Foo { Foo = "Foo" satisfies typeof FOO }

πŸ’» Use Cases

See motivating example above.

@bgenia bgenia changed the title Allow satisfies for string enum members Allow satisfies in string enum member initializers Sep 25, 2024
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants