Skip to content

const/literal handlers #334

@zacaj

Description

@zacaj

Is your feature request related to a problem? Please describe.
When trying to use ts-pattern to match cases to a string type union (eg, 'case-1' | 'case-2'), the syntax is unnecessarily verbose. I need to write () => every time, and then also add as const after each value, or repeat the options in returnType<...>() to get a proper type out

Describe the solution you'd like
It would be nice if the types for handlers accepted either a function with a given return type OR a value with that type, in the case where no data from the matcher is needed, and thus ts-pattern would have access to the specific value instead of just string to determine its returnType implicitly.
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions