Skip to content

[Request] Support non-string select / multiselect values #44

@chrissantamaria

Description

@chrissantamaria

Is your feature request related to a problem? Please describe.
The TypeScript types for select and multiselect options enforce that value fields passed extend Readonly<string>:
https://github.com/natemoo-re/clack/blob/d366a1f6e2339b5b97d0b9f42a8bdfd86333c2ba/packages/prompts/src/index.ts#L118-L120

This can be a bit cumbersome to use with non-string values, as it requires stringifying to pass to select + parsing the result returned back.

Describe the solution you'd like
Ideally (assuming no technical blockers + context I'm missing), select and multiselect could support any type of value. (perhaps naively) it looks like this could be as simple as changing the code block above to support a looser Value generic.

Describe alternatives you've considered
Stringifying + parsing as described above, though this isn't always feasible for more complex types.

Additional context
Interestingly, from my (relatively basic) testing, this only seems to be a type error. Passing in Date values works as expected - are there other types of values which may break this?

If the fix is as simple as I'm imagining, I'd be happy to open a PR and take a stab at this! However, I'm still fairly early in my testing of this library so I may be missing some important context of why this limitation exists :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions