-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Expand file tree
/
Copy pathclassPropertyInferenceFromBroaderTypeConst.symbols
More file actions
68 lines (53 loc) · 2.92 KB
/
classPropertyInferenceFromBroaderTypeConst.symbols
File metadata and controls
68 lines (53 loc) · 2.92 KB
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
//// [tests/cases/compiler/classPropertyInferenceFromBroaderTypeConst.ts] ////
=== classPropertyInferenceFromBroaderTypeConst.ts ===
// Repro from GH#62264
// Class property should infer the wider declared type (AB), not the narrowed literal type ("A")
type AB = 'A' | 'B';
>AB : Symbol(AB, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 0, 0))
const DEFAULT: AB = 'A';
>DEFAULT : Symbol(DEFAULT, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 5))
>AB : Symbol(AB, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 0, 0))
class C {
>C : Symbol(C, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 24))
D = DEFAULT;
>D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
>DEFAULT : Symbol(DEFAULT, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 5))
method() {
>method : Symbol(C.method, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 8, 16))
switch (this.D) {
>this.D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
>this : Symbol(C, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 24))
>D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
case 'A': break;
case 'B': break; // should not error
}
}
}
// D should be AB, not "A"
declare const c: C;
>c : Symbol(c, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 19, 13))
>C : Symbol(C, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 24))
declare function expectAB(x: AB): void;
>expectAB : Symbol(expectAB, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 19, 19))
>x : Symbol(x, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 20, 26))
>AB : Symbol(AB, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 0, 0))
expectAB(c.D); // ok
>expectAB : Symbol(expectAB, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 19, 19))
>c.D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
>c : Symbol(c, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 19, 13))
>D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
c.D = 'B'; // ok
>c.D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
>c : Symbol(c, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 19, 13))
>D : Symbol(C.D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 7, 9))
// Static property should work the same way
class D {
>D : Symbol(D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 22, 10))
static SD = DEFAULT;
>SD : Symbol(D.SD, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 25, 9))
>DEFAULT : Symbol(DEFAULT, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 5, 5))
}
D.SD = 'B'; // ok
>D.SD : Symbol(D.SD, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 25, 9))
>D : Symbol(D, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 22, 10))
>SD : Symbol(D.SD, Decl(classPropertyInferenceFromBroaderTypeConst.ts, 25, 9))