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

16 - Pop #28

Open
clark-t opened this issue Aug 2, 2020 · 2 comments
Open

16 - Pop #28

clark-t opened this issue Aug 2, 2020 · 2 comments
Labels
16 answer Share answers/solutions to a question

Comments

@clark-t
Copy link

clark-t commented Aug 2, 2020

works on TS3.9

type Unshift<T extends any[], K> =
    ((a: K, ...args: T) => void) extends ((...args: infer U) => void)
    ? U : never;

type Reverse<T extends any[], Target extends any[] = []> = {
    0: Target;
    1: (
        ((...args: T) => void) extends ((a: infer First, ...args: infer Rest) => void)
        ? Reverse<Rest, Unshift<Target, First>> : never
    );
}[T extends [any, ...any[]] ? 1 : 0];

type Pop<T extends any[]> =
    ((...args: Reverse<T>) => void) extends ((a: any, ...args: infer K) => void)
    ? Reverse<K> : never;
@antfu antfu added answer Share answers/solutions to a question 16 labels Aug 2, 2020
@ashi009
Copy link

ashi009 commented Sep 4, 2020

Magnificant

@noe132
Copy link

noe132 commented Sep 17, 2020

That's how things are done before rest tuple came out

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

No branches or pull requests

4 participants