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

2257 - MinusOne #4377

Open
Martynas-K opened this issue Nov 14, 2021 · 5 comments
Open

2257 - MinusOne #4377

Martynas-K opened this issue Nov 14, 2021 · 5 comments
Labels
2257 answer Share answers/solutions to a question en in English

Comments

@Martynas-K
Copy link

Will work on small numbers only, due to TS error 'Type instantiation is excessively deep and possibly infinite'

type Pop<T extends any[]> = T extends [...infer head, any] ? head : never; 

type MinusOne<T extends number, A extends any[] = []> = A['length'] extends T
  ? Pop<A>['length']
  : MinusOne<T, [...A, 0]>
@Martynas-K Martynas-K added answer Share answers/solutions to a question en in English labels Nov 14, 2021
@github-actions github-actions bot added the 2257 label Nov 14, 2021
@kstratis
Copy link

Thanks! Seems to be the next best thing after #13507.

@WisestCoder
Copy link

Is this something people can think of ?

@ZhipengYang0605
Copy link

666

@wuxin0011
Copy link

good!

@minhluudinh
Copy link

I am too stupid to understand this code. Nice code but doesn't work on all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2257 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

6 participants