You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ThisParameterType<(...args: X) => void>` expands to
`(...args: X) => void extends (this: infer U, ...args: any[]) => any`.
When `X` is an unresolved type parameter it is not possible to determine
that `any[]` is assignable to `X`. However `never` is always assignable
to `X`, so we use that instead.
tests/cases/conformance/functions/strictBindCallApply1.ts(71,17): error TS2322: Type 'number' is not assignable to type 'string'.
59
59
tests/cases/conformance/functions/strictBindCallApply1.ts(72,12): error TS2345: Argument of type '[number, string, number]' is not assignable to parameter of type '[a: number, b: string]'.
60
60
Source has 3 element(s) but target allows only 2.
61
+
tests/cases/conformance/functions/strictBindCallApply1.ts(76,5): error TS2769: No overload matches this call.
62
+
Overload 1 of 6, '(this: (this: 1, ...args: T) => void, thisArg: 1): (...args: T) => void', gave the following error.
63
+
Argument of type '2' is not assignable to parameter of type '1'.
64
+
Overload 2 of 6, '(this: (this: 1, ...args: unknown[]) => void, thisArg: 1, ...args: unknown[]): (...args: unknown[]) => void', gave the following error.
65
+
The 'this' context of type '(this: 1, ...args: T) => void' is not assignable to method's 'this' of type '(this: 1, ...args: unknown[]) => void'.
66
+
Types of parameters 'args' and 'args' are incompatible.
67
+
Type 'unknown[]' is not assignable to type 'T'.
68
+
'unknown[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown[]'.
69
+
tests/cases/conformance/functions/strictBindCallApply1.ts(81,5): error TS2769: No overload matches this call.
70
+
Overload 1 of 6, '(this: (this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void, thisArg: 1): (...args: T extends 1 ? [unknown] : [unknown, unknown]) => void', gave the following error.
71
+
Argument of type '2' is not assignable to parameter of type '1'.
72
+
Overload 2 of 6, '(this: (this: 1, ...args: unknown[]) => void, thisArg: 1, ...args: unknown[]): (...args: unknown[]) => void', gave the following error.
73
+
The 'this' context of type '(this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void' is not assignable to method's 'this' of type '(this: 1, ...args: unknown[]) => void'.
74
+
Types of parameters 'args' and 'args' are incompatible.
75
+
Type 'unknown[]' is not assignable to type 'T extends 1 ? [unknown] : [unknown, unknown]'.
!!! error TS2769: Overload 1 of 6, '(this: (this: 1, ...args: T) => void, thisArg: 1): (...args: T) => void', gave the following error.
242
+
!!! error TS2769: Argument of type '2' is not assignable to parameter of type '1'.
243
+
!!! error TS2769: Overload 2 of 6, '(this: (this: 1, ...args: unknown[]) => void, thisArg: 1, ...args: unknown[]): (...args: unknown[]) => void', gave the following error.
244
+
!!! error TS2769: The 'this' context of type '(this: 1, ...args: T) => void' is not assignable to method's 'this' of type '(this: 1, ...args: unknown[]) => void'.
245
+
!!! error TS2769: Types of parameters 'args' and 'args' are incompatible.
246
+
!!! error TS2769: Type 'unknown[]' is not assignable to type 'T'.
247
+
!!! error TS2769: 'unknown[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'unknown[]'.
248
+
}
249
+
250
+
function baz<T extends 1 | 2>(callback: (this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void) {
251
+
callback.bind(1);
252
+
callback.bind(2); // Error
253
+
~~~~~~~~~~~~~~~~
254
+
!!! error TS2769: No overload matches this call.
255
+
!!! error TS2769: Overload 1 of 6, '(this: (this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void, thisArg: 1): (...args: T extends 1 ? [unknown] : [unknown, unknown]) => void', gave the following error.
256
+
!!! error TS2769: Argument of type '2' is not assignable to parameter of type '1'.
257
+
!!! error TS2769: Overload 2 of 6, '(this: (this: 1, ...args: unknown[]) => void, thisArg: 1, ...args: unknown[]): (...args: unknown[]) => void', gave the following error.
258
+
!!! error TS2769: The 'this' context of type '(this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void' is not assignable to method's 'this' of type '(this: 1, ...args: unknown[]) => void'.
259
+
!!! error TS2769: Types of parameters 'args' and 'args' are incompatible.
260
+
!!! error TS2769: Type 'unknown[]' is not assignable to type 'T extends 1 ? [unknown] : [unknown, unknown]'.
261
+
}
262
+
263
+
// Repro from #32964
264
+
class Foo<T extends unknown[]> {
265
+
constructor() {
266
+
this.fn.bind(this);
267
+
}
268
+
269
+
fn(...args: T): void {}
270
+
}
271
+
272
+
class Bar<T extends 1 | 2> {
273
+
constructor() {
274
+
this.fn.bind(this);
275
+
}
276
+
277
+
fn(...args: T extends 1 ? [unknown] : [unknown, unknown]) {}
0 commit comments