Skip to content

Stricter types for select macro #2214

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

Open
MikaelSiidorow opened this issue Mar 31, 2025 · 2 comments · May be fixed by #2218
Open

Stricter types for select macro #2214

MikaelSiidorow opened this issue Mar 31, 2025 · 2 comments · May be fixed by #2218

Comments

@MikaelSiidorow
Copy link

Problem Description

Select macro doesn't validate choices other than other currently.

Proposed Solution

Make the macro generic over value, and the choice keys required if the value is a union type.

Potential solution:

 declare function select<T extends string | number>(
    value: T,
    options: {
      [key in T]: string
    } & {
      other: string
    }
  ): string

Alternatives Considered

I can extend the types or patch the dependency locally, but it could make sense to contribute this change to benefit everyone

Additional Context

No response

@timofei-iatsenko
Copy link
Collaborator

Feel free to create a PR, there are also type tests, include the updates to them covering your changes. Thanks!

@MikaelSiidorow
Copy link
Author

Feel free to create a PR, there are also type tests, include the updates to them covering your changes. Thanks!

Sounds good! I'll check it out soon

@MikaelSiidorow MikaelSiidorow linked a pull request Apr 4, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants