Skip to content

Allow satisfies in string enum member initializersΒ #60060

@bgenia

Description

@bgenia

πŸ” 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions