Add error elaboration test
This commit is contained in:
parent
bff843a9c9
commit
c2344e07a4
|
@ -79,9 +79,17 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Fun
|
|||
tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Comparer2<Dog>' is not assignable to type 'Comparer2<Animal>'.
|
||||
Type 'Animal' is not assignable to type 'Dog'.
|
||||
Property 'dog' is missing in type 'Animal'.
|
||||
tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
|
||||
Types of property 'onSetItem' are incompatible.
|
||||
Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
|
||||
Types of parameters 'item' and 'item' are incompatible.
|
||||
Type 'Animal' is not assignable to type 'Dog'.
|
||||
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 (29 errors) ====
|
||||
==== tests/cases/compiler/strictFunctionTypesErrors.ts (31 errors) ====
|
||||
export {}
|
||||
|
||||
|
||||
|
@ -304,4 +312,29 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Co
|
|||
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
|
||||
!!! error TS2322: Property 'dog' is missing in type 'Animal'.
|
||||
dogComparer2 = animalComparer2; // Ok
|
||||
|
||||
// Crate<T> is invariant in --strictFunctionTypes mode
|
||||
|
||||
interface Crate<T> {
|
||||
item: T;
|
||||
onSetItem: (item: T) => void;
|
||||
}
|
||||
|
||||
declare let animalCrate: Crate<Animal>;
|
||||
declare let dogCrate: Crate<Dog>;
|
||||
|
||||
// Errors below should elaborate the reason for invariance
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
|
||||
!!! error TS2322: Types of property 'onSetItem' are incompatible.
|
||||
!!! error TS2322: Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
|
||||
!!! error TS2322: Types of parameters 'item' and 'item' are incompatible.
|
||||
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
|
||||
dogCrate = animalCrate; // Error
|
||||
~~~~~~~~
|
||||
!!! 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'.
|
||||
|
|
@ -111,6 +111,21 @@ declare let dogComparer2: Comparer2<Dog>;
|
|||
|
||||
animalComparer2 = dogComparer2; // Error
|
||||
dogComparer2 = animalComparer2; // Ok
|
||||
|
||||
// Crate<T> is invariant in --strictFunctionTypes mode
|
||||
|
||||
interface Crate<T> {
|
||||
item: T;
|
||||
onSetItem: (item: T) => void;
|
||||
}
|
||||
|
||||
declare let animalCrate: Crate<Animal>;
|
||||
declare let dogCrate: Crate<Dog>;
|
||||
|
||||
// Errors below should elaborate the reason for invariance
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
|
||||
|
||||
//// [strictFunctionTypesErrors.js]
|
||||
|
@ -168,3 +183,6 @@ animalComparer1 = dogComparer1; // Ok
|
|||
dogComparer1 = animalComparer1; // Ok
|
||||
animalComparer2 = dogComparer2; // Error
|
||||
dogComparer2 = animalComparer2; // Ok
|
||||
// Errors below should elaborate the reason for invariance
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
|
|
|
@ -364,3 +364,39 @@ dogComparer2 = animalComparer2; // Ok
|
|||
>dogComparer2 : Symbol(dogComparer2, Decl(strictFunctionTypesErrors.ts, 108, 11))
|
||||
>animalComparer2 : Symbol(animalComparer2, Decl(strictFunctionTypesErrors.ts, 107, 11))
|
||||
|
||||
// Crate<T> is invariant in --strictFunctionTypes mode
|
||||
|
||||
interface Crate<T> {
|
||||
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
|
||||
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
|
||||
|
||||
item: T;
|
||||
>item : Symbol(Crate.item, Decl(strictFunctionTypesErrors.ts, 115, 20))
|
||||
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
|
||||
|
||||
onSetItem: (item: T) => void;
|
||||
>onSetItem : Symbol(Crate.onSetItem, Decl(strictFunctionTypesErrors.ts, 116, 12))
|
||||
>item : Symbol(item, Decl(strictFunctionTypesErrors.ts, 117, 16))
|
||||
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
|
||||
}
|
||||
|
||||
declare let animalCrate: Crate<Animal>;
|
||||
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
|
||||
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
|
||||
>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8))
|
||||
|
||||
declare let dogCrate: Crate<Dog>;
|
||||
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
|
||||
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
|
||||
>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33))
|
||||
|
||||
// Errors below should elaborate the reason for invariance
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
|
||||
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
|
||||
|
||||
dogCrate = animalCrate; // Error
|
||||
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
|
||||
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
|
||||
|
||||
|
|
|
@ -416,3 +416,41 @@ dogComparer2 = animalComparer2; // Ok
|
|||
>dogComparer2 : Comparer2<Dog>
|
||||
>animalComparer2 : Comparer2<Animal>
|
||||
|
||||
// Crate<T> is invariant in --strictFunctionTypes mode
|
||||
|
||||
interface Crate<T> {
|
||||
>Crate : Crate<T>
|
||||
>T : T
|
||||
|
||||
item: T;
|
||||
>item : T
|
||||
>T : T
|
||||
|
||||
onSetItem: (item: T) => void;
|
||||
>onSetItem : (item: T) => void
|
||||
>item : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
declare let animalCrate: Crate<Animal>;
|
||||
>animalCrate : Crate<Animal>
|
||||
>Crate : Crate<T>
|
||||
>Animal : Animal
|
||||
|
||||
declare let dogCrate: Crate<Dog>;
|
||||
>dogCrate : Crate<Dog>
|
||||
>Crate : Crate<T>
|
||||
>Dog : Dog
|
||||
|
||||
// Errors below should elaborate the reason for invariance
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
>animalCrate = dogCrate : Crate<Dog>
|
||||
>animalCrate : Crate<Animal>
|
||||
>dogCrate : Crate<Dog>
|
||||
|
||||
dogCrate = animalCrate; // Error
|
||||
>dogCrate = animalCrate : Crate<Animal>
|
||||
>dogCrate : Crate<Dog>
|
||||
>animalCrate : Crate<Animal>
|
||||
|
||||
|
|
|
@ -111,3 +111,18 @@ declare let dogComparer2: Comparer2<Dog>;
|
|||
|
||||
animalComparer2 = dogComparer2; // Error
|
||||
dogComparer2 = animalComparer2; // Ok
|
||||
|
||||
// Crate<T> is invariant in --strictFunctionTypes mode
|
||||
|
||||
interface Crate<T> {
|
||||
item: T;
|
||||
onSetItem: (item: T) => void;
|
||||
}
|
||||
|
||||
declare let animalCrate: Crate<Animal>;
|
||||
declare let dogCrate: Crate<Dog>;
|
||||
|
||||
// Errors below should elaborate the reason for invariance
|
||||
|
||||
animalCrate = dogCrate; // Error
|
||||
dogCrate = animalCrate; // Error
|
||||
|
|
Loading…
Reference in a new issue