/
consistentAliasVsNonAliasRecordBehavior.js
70 lines (59 loc) · 1.92 KB
/
consistentAliasVsNonAliasRecordBehavior.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//// [consistentAliasVsNonAliasRecordBehavior.ts]
// TODO: FIXME: All the below cases labeled `no error` _should be an error_, and are only prevented from so being
// by incorrect variance-based relationships
// Ref: https://github.com/Microsoft/TypeScript/issues/29698
type Record2<K extends keyof any, T> = {
[P in K]: T;
};
function defaultRecord(x: Record<'a', string>, y: Record<string, string>) {
x = y; // no error, but error expected.
}
function customRecord(x: Record2<'a', string>, y: Record2<string, string>) {
x = y; // no error, but error expected.
}
function mixed1(x: Record2<'a', string>, y: Record<string, string>) {
x = y; // error
}
function mixed2(x: Record<'a', string>, y: Record2<string, string>) {
x = y; // error
}
function defaultRecord2<T>(x: Record<'a', T>, y: Record<string, T>) {
x = y; // no error, but error expected.
}
function customRecord2<T>(x: Record2<'a', T>, y: Record2<string, T>) {
x = y; // no error, but error expected.
}
function mixed3<T>(x: Record2<'a', T>, y: Record<string, T>) {
x = y; // error
}
function mixed4<T>(x: Record<'a', T>, y: Record2<string, T>) {
x = y; // error
}
//// [consistentAliasVsNonAliasRecordBehavior.js]
// TODO: FIXME: All the below cases labeled `no error` _should be an error_, and are only prevented from so being
// by incorrect variance-based relationships
// Ref: https://github.com/Microsoft/TypeScript/issues/29698
function defaultRecord(x, y) {
x = y; // no error, but error expected.
}
function customRecord(x, y) {
x = y; // no error, but error expected.
}
function mixed1(x, y) {
x = y; // error
}
function mixed2(x, y) {
x = y; // error
}
function defaultRecord2(x, y) {
x = y; // no error, but error expected.
}
function customRecord2(x, y) {
x = y; // no error, but error expected.
}
function mixed3(x, y) {
x = y; // error
}
function mixed4(x, y) {
x = y; // error
}