Skip to content

Commit b44f6a2

Browse files
committed
Remove notes
1 parent b824cbc commit b44f6a2

5 files changed

+197
-23
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
tests/cases/compiler/checkOrderDependenceGenericAssignability.ts(24,7): error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
2+
Types of property 'child' are incompatible.
3+
Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
4+
Type 'unknown' is not assignable to type 'string'.
5+
6+
7+
==== tests/cases/compiler/checkOrderDependenceGenericAssignability.ts (1 errors) ====
8+
// #44572
9+
10+
interface Parent<A> {
11+
child: Child<A> | null;
12+
parent: Parent<A> | null;
13+
}
14+
15+
interface Child<A, B = unknown> extends Parent<A> {
16+
readonly a: A;
17+
// This field isn't necessary to the repro, but the
18+
// type parameter is, so including it
19+
readonly b: B;
20+
}
21+
22+
function fn<A>(inp: Child<A>) {
23+
// This assignability check defeats the later one
24+
const a: Child<unknown> = inp;
25+
}
26+
27+
// Allowed initialization of pu
28+
const pu: Parent<unknown> = { child: { a: 0, b: 0, child: null, parent: null }, parent: null };
29+
30+
// Should error
31+
const notString: Parent<string> = pu;
32+
~~~~~~~~~
33+
!!! error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
34+
!!! error TS2322: Types of property 'child' are incompatible.
35+
!!! error TS2322: Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
36+
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
37+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [checkOrderDependenceGenericAssignability.ts]
2+
// #44572
3+
4+
interface Parent<A> {
5+
child: Child<A> | null;
6+
parent: Parent<A> | null;
7+
}
8+
9+
interface Child<A, B = unknown> extends Parent<A> {
10+
readonly a: A;
11+
// This field isn't necessary to the repro, but the
12+
// type parameter is, so including it
13+
readonly b: B;
14+
}
15+
16+
function fn<A>(inp: Child<A>) {
17+
// This assignability check defeats the later one
18+
const a: Child<unknown> = inp;
19+
}
20+
21+
// Allowed initialization of pu
22+
const pu: Parent<unknown> = { child: { a: 0, b: 0, child: null, parent: null }, parent: null };
23+
24+
// Should error
25+
const notString: Parent<string> = pu;
26+
27+
28+
//// [checkOrderDependenceGenericAssignability.js]
29+
// #44572
30+
function fn(inp) {
31+
// This assignability check defeats the later one
32+
var a = inp;
33+
}
34+
// Allowed initialization of pu
35+
var pu = { child: { a: 0, b: 0, child: null, parent: null }, parent: null };
36+
// Should error
37+
var notString = pu;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
=== tests/cases/compiler/checkOrderDependenceGenericAssignability.ts ===
2+
// #44572
3+
4+
interface Parent<A> {
5+
>Parent : Symbol(Parent, Decl(checkOrderDependenceGenericAssignability.ts, 0, 0))
6+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 2, 17))
7+
8+
child: Child<A> | null;
9+
>child : Symbol(Parent.child, Decl(checkOrderDependenceGenericAssignability.ts, 2, 21))
10+
>Child : Symbol(Child, Decl(checkOrderDependenceGenericAssignability.ts, 5, 1))
11+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 2, 17))
12+
13+
parent: Parent<A> | null;
14+
>parent : Symbol(Parent.parent, Decl(checkOrderDependenceGenericAssignability.ts, 3, 25))
15+
>Parent : Symbol(Parent, Decl(checkOrderDependenceGenericAssignability.ts, 0, 0))
16+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 2, 17))
17+
}
18+
19+
interface Child<A, B = unknown> extends Parent<A> {
20+
>Child : Symbol(Child, Decl(checkOrderDependenceGenericAssignability.ts, 5, 1))
21+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 7, 16))
22+
>B : Symbol(B, Decl(checkOrderDependenceGenericAssignability.ts, 7, 18))
23+
>Parent : Symbol(Parent, Decl(checkOrderDependenceGenericAssignability.ts, 0, 0))
24+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 7, 16))
25+
26+
readonly a: A;
27+
>a : Symbol(Child.a, Decl(checkOrderDependenceGenericAssignability.ts, 7, 51))
28+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 7, 16))
29+
30+
// This field isn't necessary to the repro, but the
31+
// type parameter is, so including it
32+
readonly b: B;
33+
>b : Symbol(Child.b, Decl(checkOrderDependenceGenericAssignability.ts, 8, 16))
34+
>B : Symbol(B, Decl(checkOrderDependenceGenericAssignability.ts, 7, 18))
35+
}
36+
37+
function fn<A>(inp: Child<A>) {
38+
>fn : Symbol(fn, Decl(checkOrderDependenceGenericAssignability.ts, 12, 1))
39+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 14, 12))
40+
>inp : Symbol(inp, Decl(checkOrderDependenceGenericAssignability.ts, 14, 15))
41+
>Child : Symbol(Child, Decl(checkOrderDependenceGenericAssignability.ts, 5, 1))
42+
>A : Symbol(A, Decl(checkOrderDependenceGenericAssignability.ts, 14, 12))
43+
44+
// This assignability check defeats the later one
45+
const a: Child<unknown> = inp;
46+
>a : Symbol(a, Decl(checkOrderDependenceGenericAssignability.ts, 16, 7))
47+
>Child : Symbol(Child, Decl(checkOrderDependenceGenericAssignability.ts, 5, 1))
48+
>inp : Symbol(inp, Decl(checkOrderDependenceGenericAssignability.ts, 14, 15))
49+
}
50+
51+
// Allowed initialization of pu
52+
const pu: Parent<unknown> = { child: { a: 0, b: 0, child: null, parent: null }, parent: null };
53+
>pu : Symbol(pu, Decl(checkOrderDependenceGenericAssignability.ts, 20, 5))
54+
>Parent : Symbol(Parent, Decl(checkOrderDependenceGenericAssignability.ts, 0, 0))
55+
>child : Symbol(child, Decl(checkOrderDependenceGenericAssignability.ts, 20, 29))
56+
>a : Symbol(a, Decl(checkOrderDependenceGenericAssignability.ts, 20, 38))
57+
>b : Symbol(b, Decl(checkOrderDependenceGenericAssignability.ts, 20, 44))
58+
>child : Symbol(child, Decl(checkOrderDependenceGenericAssignability.ts, 20, 50))
59+
>parent : Symbol(parent, Decl(checkOrderDependenceGenericAssignability.ts, 20, 63))
60+
>parent : Symbol(parent, Decl(checkOrderDependenceGenericAssignability.ts, 20, 79))
61+
62+
// Should error
63+
const notString: Parent<string> = pu;
64+
>notString : Symbol(notString, Decl(checkOrderDependenceGenericAssignability.ts, 23, 5))
65+
>Parent : Symbol(Parent, Decl(checkOrderDependenceGenericAssignability.ts, 0, 0))
66+
>pu : Symbol(pu, Decl(checkOrderDependenceGenericAssignability.ts, 20, 5))
67+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/checkOrderDependenceGenericAssignability.ts ===
2+
// #44572
3+
4+
interface Parent<A> {
5+
child: Child<A> | null;
6+
>child : Child<A, unknown>
7+
>null : null
8+
9+
parent: Parent<A> | null;
10+
>parent : Parent<A>
11+
>null : null
12+
}
13+
14+
interface Child<A, B = unknown> extends Parent<A> {
15+
readonly a: A;
16+
>a : A
17+
18+
// This field isn't necessary to the repro, but the
19+
// type parameter is, so including it
20+
readonly b: B;
21+
>b : B
22+
}
23+
24+
function fn<A>(inp: Child<A>) {
25+
>fn : <A>(inp: Child<A>) => void
26+
>inp : Child<A, unknown>
27+
28+
// This assignability check defeats the later one
29+
const a: Child<unknown> = inp;
30+
>a : Child<unknown, unknown>
31+
>inp : Child<A, unknown>
32+
}
33+
34+
// Allowed initialization of pu
35+
const pu: Parent<unknown> = { child: { a: 0, b: 0, child: null, parent: null }, parent: null };
36+
>pu : Parent<unknown>
37+
>{ child: { a: 0, b: 0, child: null, parent: null }, parent: null } : { child: { a: number; b: number; child: null; parent: null; }; parent: null; }
38+
>child : { a: number; b: number; child: null; parent: null; }
39+
>{ a: 0, b: 0, child: null, parent: null } : { a: number; b: number; child: null; parent: null; }
40+
>a : number
41+
>0 : 0
42+
>b : number
43+
>0 : 0
44+
>child : null
45+
>null : null
46+
>parent : null
47+
>null : null
48+
>parent : null
49+
>null : null
50+
51+
// Should error
52+
const notString: Parent<string> = pu;
53+
>notString : Parent<string>
54+
>pu : Parent<unknown>
55+

tests/cases/compiler/checkOrderDependenceGenericAssignability.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
1-
/*
2-
3-
Debugging notes: variance measurement for `Parent` is getting set to
4-
`VarianceFlags.Independent`, implying that its type parameter is never
5-
witnessed at all. It arrived at this conclusion by checking the assignability
6-
of `Parent` instantiated with marker types. It first checks assignability in
7-
both directions with instantiations with super/sub-related marker types, and
8-
assignability appears to return true in both directions; however, it actually
9-
is returning `Ternary.Unknown`, due to being unable to answer questions about
10-
the assignability of the types' `parent` and `child` properties without knowing
11-
their variances. After (incorrectly) concluding that `Parent` is bivariant on `A`,
12-
it checks another set of instantiations with markers that are unrelated to each
13-
other. That too comes back as `Ternary.Unknown` but is interpreted as true, so
14-
the variance gets updated to `Independent`, since instantiating `Parent` with
15-
all kinds of different markers with different assignability to each other
16-
apparently had no effect on the instantiations' assignability to each other.
17-
18-
I'm not sure if any of those comparisons ever actually looked at `a` and `b`,
19-
which should provide some non-recursive concrete variance information. I'm also
20-
not sure if `outofbandVarianceMarkerHandler` should have been called at some point,
21-
but it was not.
22-
23-
*/
1+
// #44572
242

253
interface Parent<A> {
264
child: Child<A> | null;

0 commit comments

Comments
 (0)