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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
=== 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 : (foo: number, bar: string) => boolean
>foo : number
>bar : string
type Explicit = (...args: Tail<Parameters<MyFunctionType>>) => ReturnType<MyFunctionType>; // (bar: string) => boolean
>Explicit : (bar: string) => ReturnType<MyFunctionType>
>args : [bar: 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 : (bar: string) => boolean
function assignmentWithComplexRest<T extends any[]>() {
>assignmentWithComplexRest : <T extends any[]>() => void
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
>fn1 : (x: string, ...rest: T) => void
>x : string
>rest : T
>(x, ..._) => x : (x: string, ..._: T) => string
>x : string
>_ : T
>x : string
const fn2: (...args: never) => void = fn1;
>fn2 : (...args: never) => void
>args : never
>fn1 : (x: string, ...rest: T) => void
}
function assignmentWithComplexRest2<T extends any[]>() {
>assignmentWithComplexRest2 : <T extends any[]>() => void
const fn1: (cb: (x: string, ...rest: T) => void) => void = (cb) => {};
>fn1 : (cb: (x: string, ...rest: T) => void) => void
>cb : (x: string, ...rest: T) => void
>x : string
>rest : T
>(cb) => {} : (cb: (x: string, ...rest: T) => void) => void
>cb : (x: string, ...rest: T) => void
const fn2: (cb: (...args: never) => void) => void = fn1;
>fn2 : (cb: (...args: never) => void) => void
>cb : (...args: never) => void
>args : never
>fn1 : (cb: (x: string, ...rest: T) => void) => void
}
function assignmentWithComplexRest3<T extends any[]>() {
>assignmentWithComplexRest3 : <T extends any[]>() => void
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
>fn1 : (x: string, ...rest: T) => void
>x : string
>rest : T
>(x, ..._) => x : (x: string, ..._: T) => string
>x : string
>_ : T
>x : string
const fn2: (...args: {x: "a"} & {x: "b"}) => void = fn1;
>fn2 : (...args: { x: "a";} & { x: "b";}) => void
>args : never
>x : "a"
>x : "b"
>fn1 : (x: string, ...rest: T) => void
}
|