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

#00016 pop #21

Open
pkc918 opened this issue Aug 28, 2023 · 0 comments
Open

#00016 pop #21

pkc918 opened this issue Aug 28, 2023 · 0 comments

Comments

@pkc918
Copy link
Owner

pkc918 commented Aug 28, 2023

question

type arr1 = ['a', 'b', 'c', 'd']
type arr2 = [3, 2, 1]

type re1 = Pop<arr1> // expected to be ['a', 'b', 'c']
type re2 = Pop<arr2> // expected to be [3, 2]

implement pop, return an Array without it's last element

resolve

type Pop<T extends any[]> = T extends [...infer Prev, infer _] ? Prev : []

explain

直接通过使用 infer 变量来接受元组中的参数,... 表示多个,和js中解构类似,过滤出最后一个值就行了

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