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

Proposal: TupleToObject<TUPLE> #956

Open
aandrejevas opened this issue Sep 12, 2024 · 0 comments
Open

Proposal: TupleToObject<TUPLE> #956

aandrejevas opened this issue Sep 12, 2024 · 0 comments

Comments

@aandrejevas
Copy link

aandrejevas commented Sep 12, 2024

Summary

Given
TUPLE: Any tuple

Provide
A type that defines an object type whose keys and the corresponding value types would be the tuple indices and the corresponding tuple element types.

Potential definition

type TupleToObject<TUPLE> = { [I in keyof TUPLE & `${number}`]: TUPLE[I] }

Reference
https://stackoverflow.com/a/75746375/22340824
https://stackoverflow.com/a/70398429/22340824

Use case

Get union of bool elements indices.

const arr = [true, false, 'test'] as const;
type BoolIndices = StringToNumber<ConditionalKeys<TupleToObject<typeof arr>, boolean>>;

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants