File: genericRestTypes.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (29 lines) | stat: -rw-r--r-- 917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
=== tests/cases/compiler/genericRestTypes.ts ===
// Repro from #25793

// Gets the parameters of a function type as a tuple
// Removes the first element from a tuple
type Tail<T extends any[]> = ((...args: T) => any) extends ((head: any, ...tail: infer U) => any) ? U : never;
>Tail : Tail<T>
>args : T
>head : any
>tail : U

type MyFunctionType = (foo: number, bar: string) => boolean;
>MyFunctionType : MyFunctionType
>foo : number
>bar : string

type Explicit = (...args: Tail<Parameters<MyFunctionType>>) => ReturnType<MyFunctionType>; // (bar: string) => boolean
>Explicit : Explicit
>args : [string]

type Bind1<T extends (head: any, ...tail: any[]) => any> = (...args: Tail<Parameters<T>>) => ReturnType<T>;
>Bind1 : Bind1<T>
>head : any
>tail : any[]
>args : Tail<Parameters<T>>

type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
>Generic : Bind1<MyFunctionType>