mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 04:48:33 -05:00
Add test
This commit is contained in:
@@ -83,9 +83,18 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Cr
|
||||
tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
|
||||
Types of property 'item' are incompatible.
|
||||
Type 'Animal' is not assignable to type 'Dog'.
|
||||
tests/cases/compiler/strictFunctionTypesErrors.ts(133,1): error TS2322: Type '(f: (x: Dog) => Dog) => void' is not assignable to type '(f: (x: Animal) => Animal) => void'.
|
||||
Types of parameters 'f' and 'f' are incompatible.
|
||||
Type '(x: Animal) => Animal' is not assignable to type '(x: Dog) => Dog'.
|
||||
Type 'Animal' is not assignable to type 'Dog'.
|
||||
tests/cases/compiler/strictFunctionTypesErrors.ts(134,1): error TS2322: Type '(f: (x: Animal) => Animal) => void' is not assignable to type '(f: (x: Dog) => Dog) => void'.
|
||||
Types of parameters 'f' and 'f' are incompatible.
|
||||
Type '(x: Dog) => Dog' is not assignable to type '(x: Animal) => Animal'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'Animal' is not assignable to type 'Dog'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/strictFunctionTypesErrors.ts (31 errors) ====
|
||||
==== tests/cases/compiler/strictFunctionTypesErrors.ts (33 errors) ====
|
||||
export {}
|
||||
|
||||
|
||||
@@ -329,4 +338,22 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Cr
|
||||
!!! error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
|
||||
!!! error TS2322: Types of property 'item' are incompatible.
|
||||
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
|
||||
|
||||
// Verify that callback parameters are strictly checked
|
||||
|
||||
declare let fc1: (f: (x: Animal) => Animal) => void;
|
||||
declare let fc2: (f: (x: Dog) => Dog) => void;
|
||||
fc1 = fc2; // Error
|
||||
~~~
|
||||
!!! error TS2322: Type '(f: (x: Dog) => Dog) => void' is not assignable to type '(f: (x: Animal) => Animal) => void'.
|
||||
!!! error TS2322: Types of parameters 'f' and 'f' are incompatible.
|
||||
!!! error TS2322: Type '(x: Animal) => Animal' is not assignable to type '(x: Dog) => Dog'.
|
||||
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
|
||||
fc2 = fc1; // Error
|
||||
~~~
|
||||
!!! error TS2322: Type '(f: (x: Animal) => Animal) => void' is not assignable to type '(f: (x: Dog) => Dog) => void'.
|
||||
!!! error TS2322: Types of parameters 'f' and 'f' are incompatible.
|
||||
!!! error TS2322: Type '(x: Dog) => Dog' is not assignable to type '(x: Animal) => Animal'.
|
||||
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
|
||||
|
||||
@@ -126,6 +126,13 @@ declare let dogCrate: Crate<Dog>;
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
|
||||
// Verify that callback parameters are strictly checked
|
||||
|
||||
declare let fc1: (f: (x: Animal) => Animal) => void;
|
||||
declare let fc2: (f: (x: Dog) => Dog) => void;
|
||||
fc1 = fc2; // Error
|
||||
fc2 = fc1; // Error
|
||||
|
||||
|
||||
//// [strictFunctionTypesErrors.js]
|
||||
@@ -186,3 +193,5 @@ dogComparer2 = animalComparer2; // Ok
|
||||
// Errors below should elaborate the reason for invariance
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
fc1 = fc2; // Error
|
||||
fc2 = fc1; // Error
|
||||
|
||||
@@ -400,3 +400,27 @@ dogCrate = animalCrate; // Error
|
||||
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
|
||||
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
|
||||
|
||||
// Verify that callback parameters are strictly checked
|
||||
|
||||
declare let fc1: (f: (x: Animal) => Animal) => void;
|
||||
>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11))
|
||||
>f : Symbol(f, Decl(strictFunctionTypesErrors.ts, 130, 18))
|
||||
>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 130, 22))
|
||||
>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8))
|
||||
>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8))
|
||||
|
||||
declare let fc2: (f: (x: Dog) => Dog) => void;
|
||||
>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11))
|
||||
>f : Symbol(f, Decl(strictFunctionTypesErrors.ts, 131, 18))
|
||||
>x : Symbol(x, Decl(strictFunctionTypesErrors.ts, 131, 22))
|
||||
>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33))
|
||||
>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33))
|
||||
|
||||
fc1 = fc2; // Error
|
||||
>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11))
|
||||
>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11))
|
||||
|
||||
fc2 = fc1; // Error
|
||||
>fc2 : Symbol(fc2, Decl(strictFunctionTypesErrors.ts, 131, 11))
|
||||
>fc1 : Symbol(fc1, Decl(strictFunctionTypesErrors.ts, 130, 11))
|
||||
|
||||
|
||||
@@ -454,3 +454,29 @@ dogCrate = animalCrate; // Error
|
||||
>dogCrate : Crate<Dog>
|
||||
>animalCrate : Crate<Animal>
|
||||
|
||||
// Verify that callback parameters are strictly checked
|
||||
|
||||
declare let fc1: (f: (x: Animal) => Animal) => void;
|
||||
>fc1 : (f: (x: Animal) => Animal) => void
|
||||
>f : (x: Animal) => Animal
|
||||
>x : Animal
|
||||
>Animal : Animal
|
||||
>Animal : Animal
|
||||
|
||||
declare let fc2: (f: (x: Dog) => Dog) => void;
|
||||
>fc2 : (f: (x: Dog) => Dog) => void
|
||||
>f : (x: Dog) => Dog
|
||||
>x : Dog
|
||||
>Dog : Dog
|
||||
>Dog : Dog
|
||||
|
||||
fc1 = fc2; // Error
|
||||
>fc1 = fc2 : (f: (x: Dog) => Dog) => void
|
||||
>fc1 : (f: (x: Animal) => Animal) => void
|
||||
>fc2 : (f: (x: Dog) => Dog) => void
|
||||
|
||||
fc2 = fc1; // Error
|
||||
>fc2 = fc1 : (f: (x: Animal) => Animal) => void
|
||||
>fc2 : (f: (x: Dog) => Dog) => void
|
||||
>fc1 : (f: (x: Animal) => Animal) => void
|
||||
|
||||
|
||||
@@ -126,3 +126,10 @@ declare let dogCrate: Crate<Dog>;
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
|
||||
// Verify that callback parameters are strictly checked
|
||||
|
||||
declare let fc1: (f: (x: Animal) => Animal) => void;
|
||||
declare let fc2: (f: (x: Dog) => Dog) => void;
|
||||
fc1 = fc2; // Error
|
||||
fc2 = fc1; // Error
|
||||
|
||||
Reference in New Issue
Block a user