File: genericRestParameters3.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 (175 lines) | stat: -rw-r--r-- 10,954 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
tests/cases/conformance/types/rest/genericRestParameters3.ts(17,11): error TS2345: Argument of type '[10]' is not assignable to parameter of type '[string] | [number, boolean]'.
  Type '[10]' is not assignable to type '[string]'.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(18,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'.
  Type '[]' is not assignable to type '[number, boolean]'.
    Source has 0 element(s) but target requires 2.
tests/cases/conformance/types/rest/genericRestParameters3.ts(23,1): error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
  Types of parameters 'y' and 'args' are incompatible.
    Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
      Type '[number, boolean]' is not assignable to type '[y: string]'.
        Source has 2 element(s) but target allows only 1.
tests/cases/conformance/types/rest/genericRestParameters3.ts(24,1): error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
  Types of parameters 'y' and 'args' are incompatible.
    Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
      Type '[string]' is not assignable to type '[y: number, z: boolean]'.
        Source has 1 element(s) but target requires 2.
tests/cases/conformance/types/rest/genericRestParameters3.ts(35,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/types/rest/genericRestParameters3.ts(36,21): error TS2345: Argument of type 'number' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(37,21): error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
  Types of parameters 'cb' and 'args' are incompatible.
    Property '0' is missing in type 'CoolArray<any>' but required in type '[cb: (...args: any[]) => void]'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(44,32): error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray<number>'.
  Property 'hello' is missing in type '[10, 20]' but required in type 'CoolArray<number>'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(49,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray<never>'.
  Property 'hello' is missing in type '[]' but required in type 'CoolArray<never>'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(50,5): error TS2345: Argument of type '[number]' is not assignable to parameter of type 'CoolArray<unknown>'.
  Property 'hello' is missing in type '[number]' but required in type 'CoolArray<unknown>'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(51,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type 'CoolArray<unknown>'.
  Property 'hello' is missing in type '[number, number]' but required in type 'CoolArray<unknown>'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(52,5): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'CoolArray<number>'.
  Property 'hello' is missing in type 'number[]' but required in type 'CoolArray<number>'.
tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'.
  Type '["what"]' is not assignable to type '[number, string]'.
    Source has 1 element(s) but target requires 2.


==== tests/cases/conformance/types/rest/genericRestParameters3.ts (13 errors) ====
    declare let f1: (x: string, ...args: [string] | [number, boolean]) => void;
    declare let f2: (x: string, y: string) => void;
    declare let f3: (x: string, y: number, z: boolean) => void;
    declare let f4: (...args: [string, string] | [string, number, boolean]) => void;
    
    declare const t1: [string] | [number, boolean];
    declare const t2: readonly [string] | [number, boolean];
    declare const t3: [string] | readonly [number, boolean];
    declare const t4: readonly [string] | readonly [number, boolean];
    
    f1("foo", "abc");
    f1("foo", 10, true);
    f1("foo", ...t1);
    f1("foo", ...t2);
    f1("foo", ...t3);
    f1("foo", ...t4);
    f1("foo", 10);  // Error
              ~~
!!! error TS2345: Argument of type '[10]' is not assignable to parameter of type '[string] | [number, boolean]'.
!!! error TS2345:   Type '[10]' is not assignable to type '[string]'.
!!! error TS2345:     Type 'number' is not assignable to type 'string'.
    f1("foo");  // Error
    ~~~~~~~~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'.
!!! error TS2345:   Type '[]' is not assignable to type '[number, boolean]'.
!!! error TS2345:     Source has 0 element(s) but target requires 2.
    
    f2 = f1;
    f3 = f1;
    f4 = f1;
    f1 = f2;  // Error
    ~~
!!! error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
!!! error TS2322:   Types of parameters 'y' and 'args' are incompatible.
!!! error TS2322:     Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
!!! error TS2322:       Type '[number, boolean]' is not assignable to type '[y: string]'.
!!! error TS2322:         Source has 2 element(s) but target allows only 1.
    f1 = f3;  // Error
    ~~
!!! error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
!!! error TS2322:   Types of parameters 'y' and 'args' are incompatible.
!!! error TS2322:     Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
!!! error TS2322:       Type '[string]' is not assignable to type '[y: number, z: boolean]'.
!!! error TS2322:         Source has 1 element(s) but target requires 2.
    f1 = f4;
    
    // Repro from #26110
    
    interface CoolArray<E> extends Array<E> { 
        hello: number;
    }
    
    declare function foo<T extends any[]>(cb: (...args: T) => void): void;
    
    foo<CoolArray<any>>();     // Error
    ~~~~~~~~~~~~~~~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/types/rest/genericRestParameters3.ts:33:39: An argument for 'cb' was not provided.
    foo<CoolArray<any>>(100);  // Error
                        ~~~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
    foo<CoolArray<any>>(foo);  // Error
                        ~~~
!!! error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
!!! error TS2345:   Types of parameters 'cb' and 'args' are incompatible.
!!! error TS2345:     Property '0' is missing in type 'CoolArray<any>' but required in type '[cb: (...args: any[]) => void]'.
    
    function bar<T extends any[]>(...args: T): T {
        return args;
    }
    
    let a = bar(10, 20);
    let b = bar<CoolArray<number>>(10, 20);  // Error
                                   ~~~~~~
!!! error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray<number>'.
!!! error TS2345:   Property 'hello' is missing in type '[10, 20]' but required in type 'CoolArray<number>'.
!!! related TS2728 tests/cases/conformance/types/rest/genericRestParameters3.ts:30:5: 'hello' is declared here.
    
    declare function baz<T>(...args: CoolArray<T>): void;
    declare const ca: CoolArray<number>;
    
    baz();       // Error
    ~~~~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray<never>'.
!!! error TS2345:   Property 'hello' is missing in type '[]' but required in type 'CoolArray<never>'.
!!! related TS2728 tests/cases/conformance/types/rest/genericRestParameters3.ts:30:5: 'hello' is declared here.
    baz(1);      // Error
        ~
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type 'CoolArray<unknown>'.
!!! error TS2345:   Property 'hello' is missing in type '[number]' but required in type 'CoolArray<unknown>'.
!!! related TS2728 tests/cases/conformance/types/rest/genericRestParameters3.ts:30:5: 'hello' is declared here.
    baz(1, 2);   // Error
        ~~~~
!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type 'CoolArray<unknown>'.
!!! error TS2345:   Property 'hello' is missing in type '[number, number]' but required in type 'CoolArray<unknown>'.
!!! related TS2728 tests/cases/conformance/types/rest/genericRestParameters3.ts:30:5: 'hello' is declared here.
    baz(...ca);  // Error
        ~~~~~
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'CoolArray<number>'.
!!! error TS2345:   Property 'hello' is missing in type 'number[]' but required in type 'CoolArray<number>'.
!!! related TS2728 tests/cases/conformance/types/rest/genericRestParameters3.ts:30:5: 'hello' is declared here.
    
    // Repro from #26491
    
    declare function hmm<A extends [] | [number, string]>(...args: A): void;
    hmm(); // okay, A = []
    hmm(1, "s"); // okay, A = [1, "s"]
    hmm("what"); // no error?  A = [] | [number, string] ?
        ~~~~~~
!!! error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'.
!!! error TS2345:   Type '["what"]' is not assignable to type '[number, string]'.
!!! error TS2345:     Source has 1 element(s) but target requires 2.
    
    // Repro from #35066
    
    declare function foo2(...args: string[] | number[]): void;
    let x2: ReadonlyArray<string> = ["hello"];
    foo2(...x2);
    
    // Repros from #47754
    
    type RestParams = [y: string] | [y: number];
    
    type Signature = (x: string, ...rest: RestParams) => void;
    
    type MergedParams = Parameters<Signature>;  // [x: string, y: string] | [x: string, y: number]
    
    declare let ff1: (...rest: [string, string] | [string, number]) => void;
    declare let ff2: (x: string, ...rest: [string] | [number]) => void;
    
    ff1 = ff2;
    ff2 = ff1;
    
    function ff3<A extends unknown[]>(s1: (...args: [x: string, ...rest: A | [number]]) => void, s2: (x: string, ...rest: A | [number]) => void) {
        s1 = s2;
        s2 = s1;
    }