Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tuple to object #341

Open
FailurMan opened this issue Dec 30, 2022 · 0 comments
Open

tuple to object #341

FailurMan opened this issue Dec 30, 2022 · 0 comments

Comments

@FailurMan
Copy link
Contributor

FailurMan commented Dec 30, 2022

//使用ts实现将元组转换成对象的形式
const tuple = ["tesla", "model 3", "model X", "model Y"] as const;
type TupleToObject<T extends readonly (string | number | symbol)[]> = {
  [P in T[number]]: P;
};
type result = TupleToObject<typeof tuple>;
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant