File: genericRestTypes.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (39 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download | duplicates (4)
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
tests/cases/compiler/genericRestTypes.ts(21,11): error TS2322: Type '(cb: (x: string, ...rest: T) => void) => void' is not assignable to type '(cb: (...args: never) => void) => void'.
  Types of parameters 'cb' and 'cb' are incompatible.
    Types of parameters 'args' and 'x' are incompatible.
      Type '[x: string, ...rest: T]' is not assignable to type 'never'.


==== tests/cases/compiler/genericRestTypes.ts (1 errors) ====
    // 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;
    
    type MyFunctionType = (foo: number, bar: string) => boolean;
    
    type Explicit = (...args: Tail<Parameters<MyFunctionType>>) => ReturnType<MyFunctionType>; // (bar: string) => boolean
    
    type Bind1<T extends (head: any, ...tail: any[]) => any> = (...args: Tail<Parameters<T>>) => ReturnType<T>;
    type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
    
    function assignmentWithComplexRest<T extends any[]>() {
        const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
        const fn2: (...args: never) => void = fn1;
    }
    
    function assignmentWithComplexRest2<T extends any[]>() {
        const fn1: (cb: (x: string, ...rest: T) => void) => void = (cb) => {};
        const fn2: (cb: (...args: never) => void) => void = fn1;
              ~~~
!!! error TS2322: Type '(cb: (x: string, ...rest: T) => void) => void' is not assignable to type '(cb: (...args: never) => void) => void'.
!!! error TS2322:   Types of parameters 'cb' and 'cb' are incompatible.
!!! error TS2322:     Types of parameters 'args' and 'x' are incompatible.
!!! error TS2322:       Type '[x: string, ...rest: T]' is not assignable to type 'never'.
    }
    
    function assignmentWithComplexRest3<T extends any[]>() {
        const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
        const fn2: (...args: {x: "a"} & {x: "b"}) => void = fn1;
    }