Skip to content

Commit c2344e0

Browse files
committed
Add error elaboration test
1 parent bff843a commit c2344e0

5 files changed

+141
-1
lines changed

tests/baselines/reference/strictFunctionTypesErrors.errors.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Fun
7979
tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Comparer2<Dog>' is not assignable to type 'Comparer2<Animal>'.
8080
Type 'Animal' is not assignable to type 'Dog'.
8181
Property 'dog' is missing in type 'Animal'.
82+
tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
83+
Types of property 'onSetItem' are incompatible.
84+
Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
85+
Types of parameters 'item' and 'item' are incompatible.
86+
Type 'Animal' is not assignable to type 'Dog'.
87+
tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
88+
Types of property 'item' are incompatible.
89+
Type 'Animal' is not assignable to type 'Dog'.
8290

8391

84-
==== tests/cases/compiler/strictFunctionTypesErrors.ts (29 errors) ====
92+
==== tests/cases/compiler/strictFunctionTypesErrors.ts (31 errors) ====
8593
export {}
8694

8795

@@ -304,4 +312,29 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Co
304312
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
305313
!!! error TS2322: Property 'dog' is missing in type 'Animal'.
306314
dogComparer2 = animalComparer2; // Ok
315+
316+
// Crate<T> is invariant in --strictFunctionTypes mode
317+
318+
interface Crate<T> {
319+
item: T;
320+
onSetItem: (item: T) => void;
321+
}
322+
323+
declare let animalCrate: Crate<Animal>;
324+
declare let dogCrate: Crate<Dog>;
325+
326+
// Errors below should elaborate the reason for invariance
327+
328+
animalCrate = dogCrate; // Error
329+
~~~~~~~~~~~
330+
!!! error TS2322: Type 'Crate<Dog>' is not assignable to type 'Crate<Animal>'.
331+
!!! error TS2322: Types of property 'onSetItem' are incompatible.
332+
!!! error TS2322: Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'.
333+
!!! error TS2322: Types of parameters 'item' and 'item' are incompatible.
334+
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
335+
dogCrate = animalCrate; // Error
336+
~~~~~~~~
337+
!!! error TS2322: Type 'Crate<Animal>' is not assignable to type 'Crate<Dog>'.
338+
!!! error TS2322: Types of property 'item' are incompatible.
339+
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
307340

tests/baselines/reference/strictFunctionTypesErrors.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ declare let dogComparer2: Comparer2<Dog>;
111111

112112
animalComparer2 = dogComparer2; // Error
113113
dogComparer2 = animalComparer2; // Ok
114+
115+
// Crate<T> is invariant in --strictFunctionTypes mode
116+
117+
interface Crate<T> {
118+
item: T;
119+
onSetItem: (item: T) => void;
120+
}
121+
122+
declare let animalCrate: Crate<Animal>;
123+
declare let dogCrate: Crate<Dog>;
124+
125+
// Errors below should elaborate the reason for invariance
126+
127+
animalCrate = dogCrate; // Error
128+
dogCrate = animalCrate; // Error
114129

115130

116131
//// [strictFunctionTypesErrors.js]
@@ -168,3 +183,6 @@ animalComparer1 = dogComparer1; // Ok
168183
dogComparer1 = animalComparer1; // Ok
169184
animalComparer2 = dogComparer2; // Error
170185
dogComparer2 = animalComparer2; // Ok
186+
// Errors below should elaborate the reason for invariance
187+
animalCrate = dogCrate; // Error
188+
dogCrate = animalCrate; // Error

tests/baselines/reference/strictFunctionTypesErrors.symbols

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,39 @@ dogComparer2 = animalComparer2; // Ok
364364
>dogComparer2 : Symbol(dogComparer2, Decl(strictFunctionTypesErrors.ts, 108, 11))
365365
>animalComparer2 : Symbol(animalComparer2, Decl(strictFunctionTypesErrors.ts, 107, 11))
366366

367+
// Crate<T> is invariant in --strictFunctionTypes mode
368+
369+
interface Crate<T> {
370+
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
371+
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
372+
373+
item: T;
374+
>item : Symbol(Crate.item, Decl(strictFunctionTypesErrors.ts, 115, 20))
375+
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
376+
377+
onSetItem: (item: T) => void;
378+
>onSetItem : Symbol(Crate.onSetItem, Decl(strictFunctionTypesErrors.ts, 116, 12))
379+
>item : Symbol(item, Decl(strictFunctionTypesErrors.ts, 117, 16))
380+
>T : Symbol(T, Decl(strictFunctionTypesErrors.ts, 115, 16))
381+
}
382+
383+
declare let animalCrate: Crate<Animal>;
384+
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
385+
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
386+
>Animal : Symbol(Animal, Decl(strictFunctionTypesErrors.ts, 87, 8))
387+
388+
declare let dogCrate: Crate<Dog>;
389+
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
390+
>Crate : Symbol(Crate, Decl(strictFunctionTypesErrors.ts, 111, 31))
391+
>Dog : Symbol(Dog, Decl(strictFunctionTypesErrors.ts, 89, 33))
392+
393+
// Errors below should elaborate the reason for invariance
394+
395+
animalCrate = dogCrate; // Error
396+
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
397+
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
398+
399+
dogCrate = animalCrate; // Error
400+
>dogCrate : Symbol(dogCrate, Decl(strictFunctionTypesErrors.ts, 121, 11))
401+
>animalCrate : Symbol(animalCrate, Decl(strictFunctionTypesErrors.ts, 120, 11))
402+

tests/baselines/reference/strictFunctionTypesErrors.types

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,41 @@ dogComparer2 = animalComparer2; // Ok
416416
>dogComparer2 : Comparer2<Dog>
417417
>animalComparer2 : Comparer2<Animal>
418418

419+
// Crate<T> is invariant in --strictFunctionTypes mode
420+
421+
interface Crate<T> {
422+
>Crate : Crate<T>
423+
>T : T
424+
425+
item: T;
426+
>item : T
427+
>T : T
428+
429+
onSetItem: (item: T) => void;
430+
>onSetItem : (item: T) => void
431+
>item : T
432+
>T : T
433+
}
434+
435+
declare let animalCrate: Crate<Animal>;
436+
>animalCrate : Crate<Animal>
437+
>Crate : Crate<T>
438+
>Animal : Animal
439+
440+
declare let dogCrate: Crate<Dog>;
441+
>dogCrate : Crate<Dog>
442+
>Crate : Crate<T>
443+
>Dog : Dog
444+
445+
// Errors below should elaborate the reason for invariance
446+
447+
animalCrate = dogCrate; // Error
448+
>animalCrate = dogCrate : Crate<Dog>
449+
>animalCrate : Crate<Animal>
450+
>dogCrate : Crate<Dog>
451+
452+
dogCrate = animalCrate; // Error
453+
>dogCrate = animalCrate : Crate<Animal>
454+
>dogCrate : Crate<Dog>
455+
>animalCrate : Crate<Animal>
456+

tests/cases/compiler/strictFunctionTypesErrors.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,18 @@ declare let dogComparer2: Comparer2<Dog>;
111111

112112
animalComparer2 = dogComparer2; // Error
113113
dogComparer2 = animalComparer2; // Ok
114+
115+
// Crate<T> is invariant in --strictFunctionTypes mode
116+
117+
interface Crate<T> {
118+
item: T;
119+
onSetItem: (item: T) => void;
120+
}
121+
122+
declare let animalCrate: Crate<Animal>;
123+
declare let dogCrate: Crate<Dog>;
124+
125+
// Errors below should elaborate the reason for invariance
126+
127+
animalCrate = dogCrate; // Error
128+
dogCrate = animalCrate; // Error

0 commit comments

Comments
 (0)