mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
131 lines
7.2 KiB
Plaintext
131 lines
7.2 KiB
Plaintext
genericCallWithGenericSignatureArguments2.ts(10,51): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => number'.
|
|
Types of parameters 'x' and 'x' are incompatible.
|
|
Type 'number' is not assignable to type 'string'.
|
|
genericCallWithGenericSignatureArguments2.ts(15,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
|
|
'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
|
|
genericCallWithGenericSignatureArguments2.ts(16,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
|
|
genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
|
|
Types of parameters 'a' and 'x' are incompatible.
|
|
Type 'Date' is not assignable to type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'Date'.
|
|
genericCallWithGenericSignatureArguments2.ts(37,43): error TS2322: Type 'F' is not assignable to type 'E'.
|
|
genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
|
|
'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
|
|
genericCallWithGenericSignatureArguments2.ts(51,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
|
|
genericCallWithGenericSignatureArguments2.ts(60,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
|
|
Types of parameters 'a' and 'x' are incompatible.
|
|
Type 'Date' is not assignable to type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'Date'.
|
|
genericCallWithGenericSignatureArguments2.ts(67,51): error TS2304: Cannot find name 'U'.
|
|
genericCallWithGenericSignatureArguments2.ts(67,57): error TS2304: Cannot find name 'U'.
|
|
|
|
|
|
==== genericCallWithGenericSignatureArguments2.ts (10 errors) ====
|
|
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
|
|
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
|
|
|
|
namespace onlyT {
|
|
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
|
|
~~~~~~~~~~~~~~~~~
|
|
!!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => number'.
|
|
!!! error TS2345: Types of parameters 'x' and 'x' are incompatible.
|
|
!!! error TS2345: Type 'number' is not assignable to type 'string'.
|
|
|
|
function other2<T extends Date>(x: T) {
|
|
var r7 = foo((a: T) => a, (b: T) => b); // T => T
|
|
// BUG 835518
|
|
var r9 = r7(new Date()); // should be ok
|
|
~~~~~~~~~~
|
|
!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
|
|
!!! error TS2345: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
|
|
var r10 = r7(1); // error
|
|
~
|
|
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
|
|
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
|
|
}
|
|
|
|
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
function other3<T extends RegExp>(x: T) {
|
|
var r7 = foo2((a: T) => a, (b: T) => b); // error
|
|
~~~~~~~~~~~
|
|
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
|
|
!!! error TS2345: Types of parameters 'a' and 'x' are incompatible.
|
|
!!! error TS2345: Type 'Date' is not assignable to type 'T'.
|
|
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Date'.
|
|
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
|
|
}
|
|
|
|
enum E { A }
|
|
enum F { A }
|
|
|
|
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
|
|
~~~
|
|
!!! error TS2322: Type 'F' is not assignable to type 'E'.
|
|
!!! related TS6502 genericCallWithGenericSignatureArguments2.ts:32:47: The expected type comes from the return type of this signature.
|
|
}
|
|
|
|
namespace TU {
|
|
function foo<T, U>(a: (x: T) => T, b: (x: U) => U) {
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
|
|
|
|
function other2<T extends Date>(x: T) {
|
|
var r7 = foo((a: T) => a, (b: T) => b);
|
|
var r9 = r7(new Date());
|
|
~~~~~~~~~~
|
|
!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
|
|
!!! error TS2345: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'.
|
|
var r10 = r7(1);
|
|
~
|
|
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
|
|
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
|
|
}
|
|
|
|
function foo2<T extends Date, U extends Date>(a: (x: T) => T, b: (x: U) => U) {
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
function other3<T extends RegExp>(x: T) {
|
|
var r7 = foo2((a: T) => a, (b: T) => b);
|
|
~~~~~~~~~~~
|
|
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
|
|
!!! error TS2345: Types of parameters 'a' and 'x' are incompatible.
|
|
!!! error TS2345: Type 'Date' is not assignable to type 'T'.
|
|
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Date'.
|
|
var r7b = foo2((a) => a, (b) => b);
|
|
}
|
|
|
|
enum E { A }
|
|
enum F { A }
|
|
|
|
function foo3<T>(x: T, a: (x: T) => T, b: (x: U) => U) {
|
|
~
|
|
!!! error TS2304: Cannot find name 'U'.
|
|
~
|
|
!!! error TS2304: Cannot find name 'U'.
|
|
var r!: (x: T) => T;
|
|
return r;
|
|
}
|
|
|
|
var r7 = foo3(E.A, (x) => E.A, (x) => F.A);
|
|
} |