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

1-5-实现Tuple to Object #5

Open
wadeewang opened this issue Mar 3, 2023 · 0 comments
Open

1-5-实现Tuple to Object #5

wadeewang opened this issue Mar 3, 2023 · 0 comments

Comments

@wadeewang
Copy link
Owner

//你的答案
我们需要从数组中获取所有的值,并将其作为新对象中的键和值。

这个使用索引类型很容易。我们可以通过使用 T[number]从数组中获取值。在映射类型的 帮助下,我们可以迭代 T[number]中的这些值,并返回一个新的类型,其中键和值  T[number]的类型:

type TupleToObject<T extends readonly string[]> = { [K in T[number]]: K };
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

No branches or pull requests

1 participant