Skip to content

Commit d70d505

Browse files
committed
Accept new baselines
1 parent 8f860f6 commit d70d505

File tree

4 files changed

+655
-0
lines changed

4 files changed

+655
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
tests/cases/conformance/types/conditional/conditionalTypes2.ts(19,5): error TS2322: Type 'Covariant<A>' is not assignable to type 'Covariant<B>'.
2+
Type 'A' is not assignable to type 'B'.
3+
Property 'b' is missing in type 'A'.
4+
tests/cases/conformance/types/conditional/conditionalTypes2.ts(23,5): error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
5+
Type 'A' is not assignable to type 'B'.
6+
tests/cases/conformance/types/conditional/conditionalTypes2.ts(28,5): error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
7+
Type 'A' is not assignable to type 'B'.
8+
tests/cases/conformance/types/conditional/conditionalTypes2.ts(29,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
9+
Types of property 'foo' are incompatible.
10+
Type 'A' is not assignable to type 'B'.
11+
12+
13+
==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (4 errors) ====
14+
interface Covariant<T> {
15+
foo: T extends string ? T : number;
16+
}
17+
18+
interface Contravariant<T> {
19+
foo: T extends string ? keyof T : number;
20+
}
21+
22+
interface Invariant<T> {
23+
foo: T extends string ? keyof T : T;
24+
}
25+
26+
interface A { a: string }
27+
interface B extends A { b: string }
28+
29+
30+
function f1(a: Covariant<A>, b: Covariant<B>) {
31+
a = b;
32+
b = a; // Error
33+
~
34+
!!! error TS2322: Type 'Covariant<A>' is not assignable to type 'Covariant<B>'.
35+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
36+
!!! error TS2322: Property 'b' is missing in type 'A'.
37+
}
38+
39+
function f2(a: Contravariant<A>, b: Contravariant<B>) {
40+
a = b; // Error
41+
~
42+
!!! error TS2322: Type 'Contravariant<B>' is not assignable to type 'Contravariant<A>'.
43+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
44+
b = a;
45+
}
46+
47+
function f3(a: Invariant<A>, b: Invariant<B>) {
48+
a = b; // Error
49+
~
50+
!!! error TS2322: Type 'Invariant<B>' is not assignable to type 'Invariant<A>'.
51+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
52+
b = a; // Error
53+
~
54+
!!! error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
55+
!!! error TS2322: Types of property 'foo' are incompatible.
56+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
57+
}
58+
59+
// Repros from #22860
60+
61+
class Opt<T> {
62+
toVector(): Vector<T> {
63+
return <any>undefined;
64+
}
65+
}
66+
67+
interface Seq<T> {
68+
tail(): Opt<Seq<T>>;
69+
}
70+
71+
class Vector<T> implements Seq<T> {
72+
tail(): Opt<Vector<T>> {
73+
return <any>undefined;
74+
}
75+
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
76+
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
77+
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
78+
return <any>undefined;
79+
}
80+
}
81+
82+
interface A1<T> {
83+
bat: B1<A1<T>>;
84+
}
85+
86+
interface B1<T> extends A1<T> {
87+
bat: B1<B1<T>>;
88+
boom: T extends any ? true : true
89+
}
90+
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//// [conditionalTypes2.ts]
2+
interface Covariant<T> {
3+
foo: T extends string ? T : number;
4+
}
5+
6+
interface Contravariant<T> {
7+
foo: T extends string ? keyof T : number;
8+
}
9+
10+
interface Invariant<T> {
11+
foo: T extends string ? keyof T : T;
12+
}
13+
14+
interface A { a: string }
15+
interface B extends A { b: string }
16+
17+
18+
function f1(a: Covariant<A>, b: Covariant<B>) {
19+
a = b;
20+
b = a; // Error
21+
}
22+
23+
function f2(a: Contravariant<A>, b: Contravariant<B>) {
24+
a = b; // Error
25+
b = a;
26+
}
27+
28+
function f3(a: Invariant<A>, b: Invariant<B>) {
29+
a = b; // Error
30+
b = a; // Error
31+
}
32+
33+
// Repros from #22860
34+
35+
class Opt<T> {
36+
toVector(): Vector<T> {
37+
return <any>undefined;
38+
}
39+
}
40+
41+
interface Seq<T> {
42+
tail(): Opt<Seq<T>>;
43+
}
44+
45+
class Vector<T> implements Seq<T> {
46+
tail(): Opt<Vector<T>> {
47+
return <any>undefined;
48+
}
49+
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
50+
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
51+
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
52+
return <any>undefined;
53+
}
54+
}
55+
56+
interface A1<T> {
57+
bat: B1<A1<T>>;
58+
}
59+
60+
interface B1<T> extends A1<T> {
61+
bat: B1<B1<T>>;
62+
boom: T extends any ? true : true
63+
}
64+
65+
66+
//// [conditionalTypes2.js]
67+
"use strict";
68+
function f1(a, b) {
69+
a = b;
70+
b = a; // Error
71+
}
72+
function f2(a, b) {
73+
a = b; // Error
74+
b = a;
75+
}
76+
function f3(a, b) {
77+
a = b; // Error
78+
b = a; // Error
79+
}
80+
// Repros from #22860
81+
var Opt = /** @class */ (function () {
82+
function Opt() {
83+
}
84+
Opt.prototype.toVector = function () {
85+
return undefined;
86+
};
87+
return Opt;
88+
}());
89+
var Vector = /** @class */ (function () {
90+
function Vector() {
91+
}
92+
Vector.prototype.tail = function () {
93+
return undefined;
94+
};
95+
Vector.prototype.partition2 = function (predicate) {
96+
return undefined;
97+
};
98+
return Vector;
99+
}());
100+
101+
102+
//// [conditionalTypes2.d.ts]
103+
interface Covariant<T> {
104+
foo: T extends string ? T : number;
105+
}
106+
interface Contravariant<T> {
107+
foo: T extends string ? keyof T : number;
108+
}
109+
interface Invariant<T> {
110+
foo: T extends string ? keyof T : T;
111+
}
112+
interface A {
113+
a: string;
114+
}
115+
interface B extends A {
116+
b: string;
117+
}
118+
declare function f1(a: Covariant<A>, b: Covariant<B>): void;
119+
declare function f2(a: Contravariant<A>, b: Contravariant<B>): void;
120+
declare function f3(a: Invariant<A>, b: Invariant<B>): void;
121+
declare class Opt<T> {
122+
toVector(): Vector<T>;
123+
}
124+
interface Seq<T> {
125+
tail(): Opt<Seq<T>>;
126+
}
127+
declare class Vector<T> implements Seq<T> {
128+
tail(): Opt<Vector<T>>;
129+
partition2<U extends T>(predicate: (v: T) => v is U): [Vector<U>, Vector<Exclude<T, U>>];
130+
partition2(predicate: (x: T) => boolean): [Vector<T>, Vector<T>];
131+
}
132+
interface A1<T> {
133+
bat: B1<A1<T>>;
134+
}
135+
interface B1<T> extends A1<T> {
136+
bat: B1<B1<T>>;
137+
boom: T extends any ? true : true;
138+
}

0 commit comments

Comments
 (0)