File tree

21 files changed

+152
-98
lines changed

21 files changed

+152
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"character": 1
3333
}
3434
},
35-
"newText": "\nfunction newFunction(): {| a: number, barr: number, fooo: number |} {\n // comment before\n let fooo = 3; // selected\n let barr = 4; // selected\n const a = 3; // selected\n return { a, barr, fooo };\n}"
35+
"newText": "\nfunction newFunction(): {| a: 3, barr: number, fooo: number |} {\n // comment before\n let fooo = 3; // selected\n let barr = 4; // selected\n const a = 3; // selected\n return { a, barr, fooo };\n}"
3636
}
3737
]
3838
}
@@ -78,7 +78,7 @@
7878
"character": 15
7979
}
8080
},
81-
"newText": "function newFunction(): {| a: number, barr: number, fooo: number |} {\n // comment before\n let fooo = 3; // selected\n let barr = 4; // selected\n const a = 3; // selected\n return { a, barr, fooo };\n }"
81+
"newText": "function newFunction(): {| a: 3, barr: number, fooo: number |} {\n // comment before\n let fooo = 3; // selected\n let barr = 4; // selected\n const a = 3; // selected\n return { a, barr, fooo };\n }"
8282
}
8383
]
8484
}
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"items": [
66
{
77
"label": "foobar",
8-
"kind": 6,
9-
"detail": "string",
8+
"kind": 12,
9+
"detail": "\"\"",
1010
"sortText": "00000000000000000000",
1111
"insertTextFormat": 1,
1212
"textEdit": {
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"items": [
66
{
77
"label": "actors",
8-
"kind": 6,
9-
"detail": "number",
8+
"kind": 12,
9+
"detail": "3",
1010
"sortText": "00000000000000000000",
1111
"insertTextFormat": 1,
1212
"textEdit": {
@@ -143,8 +143,8 @@
143143
},
144144
{
145145
"label": "actoooooooor",
146-
"kind": 6,
147-
"detail": "number",
146+
"kind": 12,
147+
"detail": "3",
148148
"sortText": "00000000000000000003",
149149
"insertTextFormat": 1,
150150
"textEdit": {
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,8 @@ module.exports = (suite(
14761476
},
14771477
{
14781478
label: 'x',
1479-
kind: 6,
1480-
detail: 'number',
1479+
kind: 12,
1480+
detail: '15',
14811481
sortText: '00000000000000000041',
14821482
insertTextFormat: 1,
14831483
textEdit: {
@@ -3483,8 +3483,8 @@ b.te
34833483
},
34843484
{
34853485
label: 'x',
3486-
kind: 6,
3487-
detail: 'number',
3486+
kind: 12,
3487+
detail: '15',
34883488
sortText: '00000000000000000042',
34893489
insertTextFormat: 1,
34903490
textEdit: {
@@ -4996,8 +4996,8 @@ b.te
49964996
},
49974997
{
49984998
label: 'x',
4999-
kind: 6,
5000-
detail: 'number',
4999+
kind: 12,
5000+
detail: '15',
50015001
sortText: '00000000000000000040',
50025002
insertTextFormat: 1,
50035003
textEdit: {
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ module Opts = struct
251251
multi_platform_extension_group_mapping = [];
252252
multi_platform_ambient_supports_platform_directory_overrides = [];
253253
munge_underscores = false;
254-
natural_inference_local_primitive_literals = Options.NaturalInferenceLevel.Off;
254+
natural_inference_local_primitive_literals = Options.NaturalInferenceLevel.Partial;
255255
natural_inference_local_primitive_literals_full_includes = [];
256256
no_flowlib = false;
257257
no_unchecked_indexed_access = false;
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
>>> test.js (#changes: 7)
22
// @flow
33

4-
let x: {| foo?: number |} = {}; // add annot
4+
let x: {| foo?: 3 |} = {}; // add annot
55
x.foo = 3;
66

7-
let y: {| foo?: string |} = {}; // add annot
7+
let y: {| foo?: "" |} = {}; // add annot
88
if (x) {
99
y.foo = '';
1010
}
1111

12-
let z: {| bar?: string, foo?: number |} = {}; // add annot
12+
let z: {| bar?: "", foo?: 3 |} = {}; // add annot
1313
z.foo = 3;
1414
if (x) {
1515
z.bar = '';
1616
}
1717

18-
let q: {| bar?: string, foo: number |} = {foo: 3}; // add annot
18+
let q: {| bar?: "", foo: number |} = {foo: 3}; // add annot
1919
if (x) {
2020
q.bar = '';
2121
}
@@ -26,14 +26,14 @@ if (x) {
2626
s.bar = '';
2727
}
2828

29-
let d: {| foo?: string | number |} = {}; // should only annot foo once
29+
let d: {| foo?: "" | 3 |} = {}; // should only annot foo once
3030
if (x) {
3131
d.foo = 3;
3232
} else {
3333
d.foo = '';
3434
}
3535

36-
let e: {| foo?: string |} = {}; // should only annot foo once
36+
let e: {| foo?: "" |} = {}; // should only annot foo once
3737
if (x) {
3838
e.foo = '';
3939
} else {
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Flags: --pretty --imports
140140

141141
components.js:21:16
142142
Flags: --pretty --imports
143-
{"result":[{"name":"xaaa","type":"number"},{"name":"xbbb","type":"string"}]}
143+
{"result":[{"name":"xaaa","type":"42"},{"name":"xbbb","type":"string"}]}
144144

145145
react_type_namespace.js:3:18
146146
Flags: --pretty
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ References:
9999
^^^^^^^ [2]
100100

101101

102+
Error --------------------------------------------------------------------------------------------------- bigint.js:47:3
103+
104+
Cannot cast `x` to `typeof b` because bigint literal `0n` [1] is incompatible with bigint [2]. [incompatible-cast]
105+
106+
bigint.js:47:3
107+
47| x as typeof b; // ERROR typeof b is `1n`
108+
^
109+
110+
References:
111+
bigint.js:44:20
112+
44| declare const x: 0n | 1n;
113+
^^ [1]
114+
bigint.js:47:8
115+
47| x as typeof b; // ERROR typeof b is `1n`
116+
^^^^^^^^ [2]
117+
118+
102119
Error --------------------------------------------------------------------------------------------------- bigint.js:49:3
103120

104121
Cannot cast `x` to union type because union type [1] is incompatible with union type [2]. Type union type [1] includes
@@ -480,4 +497,4 @@ References:
480497

481498

482499

483-
Found 36 errors
500+
Found 37 errors
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if (b) {} // error
4444
declare const x: 0n | 1n;
4545
x as bigint; // OK
4646
const b = 1n; // OK
47-
x as typeof b; // OK - `typeof 1n` is `bigint`
47+
x as typeof b; // ERROR typeof b is `1n`
4848
x as 1n | 0n; // OK
4949
x as 2n | 3n; // ERROR
5050
}
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
"end":6
226226
},
227227
{
228-
"type":"number",
228+
"type":"0",
229229
"reasons":[],
230230
"loc":{
231231
"source":"test.js",
@@ -1053,7 +1053,7 @@
10531053
"end":9
10541054
},
10551055
{
1056-
"type":"string",
1056+
"type":"\"\"",
10571057
"reasons":[],
10581058
"loc":{
10591059
"source":"predicates.js",
@@ -1143,7 +1143,7 @@
11431143
"end":9
11441144
},
11451145
{
1146-
"type":"string",
1146+
"type":"\"\"",
11471147
"reasons":[],
11481148
"loc":{
11491149
"source":"predicates.js",
@@ -1533,7 +1533,7 @@ elem_call.js:13:1-10: (string) => string
15331533
elem_call.js:13:1-14: string
15341534
elem_call.js:13:7-9: string
15351535
elem_call.js:13:7-9: string
1536-
elem_call.js:13:12-13: string
1536+
elem_call.js:13:12-13: ""
15371537
elem_call.js:17:1-5: {[key: "a"]: () => {...}} | void
15381538
elem_call.js:17:1-5: {[key: "a"]: () => {...}} | void
15391539
elem_call.js:17:1-8: any (implicit)
@@ -1545,23 +1545,23 @@ optional_calls.js:7:3: void | F
15451545
optional_calls.js:7:3: void | F
15461546
optional_calls.js:7:3-12: void
15471547
optional_calls.js:7:3-12: void
1548-
optional_calls.js:7:7-11: string
1548+
optional_calls.js:7:7-11: "abc"
15491549
optional_calls.js:12:3: ?{m: F, ...}
15501550
optional_calls.js:12:3: ?{m: F, ...}
15511551
optional_calls.js:12:3-6: F
15521552
optional_calls.js:12:3-6: ?{m: F, ...}
15531553
optional_calls.js:12:3-13: void
15541554
optional_calls.js:12:3-13: void
15551555
optional_calls.js:12:6: F
1556-
optional_calls.js:12:8-12: string
1556+
optional_calls.js:12:8-12: "abc"
15571557
optional_calls.js:17:3: ?{[key: string]: F}
15581558
optional_calls.js:17:3: ?{[key: string]: F}
15591559
optional_calls.js:17:3-12: F
15601560
optional_calls.js:17:3-12: ?{[key: string]: F}
15611561
optional_calls.js:17:3-19: void
15621562
optional_calls.js:17:3-19: void
1563-
optional_calls.js:17:7-11: string
1564-
optional_calls.js:17:14-18: string
1563+
optional_calls.js:17:7-11: "abc"
1564+
optional_calls.js:17:14-18: "abc"
15651565
optional_calls.js:22:3: ?{m: {n: F, ...}, ...}
15661566
optional_calls.js:22:3: ?{m: {n: F, ...}, ...}
15671567
optional_calls.js:22:3-6: void | {n: F, ...}
@@ -1572,17 +1572,17 @@ optional_calls.js:22:3-15: void
15721572
optional_calls.js:22:3-15: void
15731573
optional_calls.js:22:6: void | {n: F, ...}
15741574
optional_calls.js:22:8: F
1575-
optional_calls.js:22:10-14: string
1575+
optional_calls.js:22:10-14: "abc"
15761576
optional_calls.js:27:3: {m: ?F, ...}
15771577
optional_calls.js:27:3: {m: ?F, ...}
15781578
optional_calls.js:27:3-5: ?F
15791579
optional_calls.js:27:3-14: void
15801580
optional_calls.js:27:3-14: void
15811581
optional_calls.js:27:5: ?F
1582-
optional_calls.js:27:9-13: string
1582+
optional_calls.js:27:9-13: "abc"
15831583
optional_calls.js:33:5: {f: F, ...}
15841584
optional_calls.js:33:5: {f: F, ...}
15851585
optional_calls.js:33:5-7: F
15861586
optional_calls.js:33:5-14: void
15871587
optional_calls.js:33:7: F
1588-
optional_calls.js:33:9-13: string
1588+
optional_calls.js:33:9-13: "abc"
Original file line numberDiff line numberDiff line change
@@ -4450,7 +4450,8 @@ Cannot instantiate `$ReadOnly` because enum `E` [1] is not an object. [not-an-ob
44504450

44514451
Error -------------------------------------------------------------------------------------------- utility-types.js:22:1
44524452

4453-
Cannot cast `'A'` to key set because property `A` is missing in enum `E` [1]. [incompatible-use]
4453+
Cannot cast `'A'` to key set because an index signature declaring the expected key / value type is missing in enum
4454+
`E` [1]. [incompatible-use]
44544455

44554456
utility-types.js:22:1
44564457
22| 'A' as $Keys<typeof E>; // Error: TODO: improve error
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,44 @@ References:
972972
^^^^^^^ [2]
973973

974974

975+
Error --------------------------------------------------------------------------------------------- upper_non_t.js:152:3
976+
977+
Cannot cast `d1` to object type because number [1] is incompatible with number [2] in property `bar`. This property is
978+
invariantly typed. See https://flow.org/en/docs/faq/#why-cant-i-pass-a-string-to-a-function-that-takes-a-string-number.
979+
[incompatible-cast]
980+
981+
upper_non_t.js:152:3
982+
152| d1 as {|foo: string, bar: number|}; // error T is inferred as {foo: string, bar: 3}
983+
^^
984+
985+
References:
986+
upper_non_t.js:152:29
987+
152| d1 as {|foo: string, bar: number|}; // error T is inferred as {foo: string, bar: 3}
988+
^^^^^^ [1]
989+
upper_non_t.js:149:26
990+
149| const d1 = Diff1({bar: 3});
991+
^ [2]
992+
993+
994+
Error --------------------------------------------------------------------------------------------- upper_non_t.js:153:3
995+
996+
Cannot cast `d1` to object type because number [1] is incompatible with number [2] in property `bar`. This property is
997+
invariantly typed. See https://flow.org/en/docs/faq/#why-cant-i-pass-a-string-to-a-function-that-takes-a-string-number.
998+
[incompatible-cast]
999+
1000+
upper_non_t.js:153:3
1001+
153| d1 as {|foo: string | number, bar: number|}; // error
1002+
^^
1003+
1004+
References:
1005+
upper_non_t.js:153:38
1006+
153| d1 as {|foo: string | number, bar: number|}; // error
1007+
^^^^^^ [1]
1008+
upper_non_t.js:149:26
1009+
149| const d1 = Diff1({bar: 3});
1010+
^ [2]
1011+
1012+
9751013
Error --------------------------------------------------------------------------------------------- upper_non_t.js:153:3
9761014

9771015
Cannot cast `d1` to object type because number [1] is incompatible with string [2] in property `foo`. This property is
@@ -1102,6 +1140,25 @@ References:
11021140
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2]
11031141

11041142

1143+
Error --------------------------------------------------------------------------------------------- upper_non_t.js:168:3
1144+
1145+
Cannot cast `d3` to object type because number [1] is incompatible with number [2] in property `bar`. This property is
1146+
invariantly typed. See https://flow.org/en/docs/faq/#why-cant-i-pass-a-string-to-a-function-that-takes-a-string-number.
1147+
[incompatible-cast]
1148+
1149+
upper_non_t.js:168:3
1150+
168| d3 as {|foo: string, bar: number|}; // error
1151+
^^
1152+
1153+
References:
1154+
upper_non_t.js:168:29
1155+
168| d3 as {|foo: string, bar: number|}; // error
1156+
^^^^^^ [1]
1157+
upper_non_t.js:163:26
1158+
163| const d3 = Diff3({bar: 3});
1159+
^ [2]
1160+
1161+
11051162
Error -------------------------------------------------------------------------------------------- upper_non_t.js:171:15
11061163

11071164
Cannot call `Diff4` because string [1] is incompatible with number [2]. [incompatible-call]
@@ -1116,5 +1173,24 @@ References:
11161173
^^^^^^ [2]
11171174

11181175

1176+
Error --------------------------------------------------------------------------------------------- upper_non_t.js:176:3
1177+
1178+
Cannot cast `d4` to object type because number [1] is incompatible with number [2] in property `bar`. This property is
1179+
invariantly typed. See https://flow.org/en/docs/faq/#why-cant-i-pass-a-string-to-a-function-that-takes-a-string-number.
1180+
[incompatible-cast]
1181+
1182+
upper_non_t.js:176:3
1183+
176| d4 as {|[string]: number, bar: number|};
1184+
^^
1185+
1186+
References:
1187+
upper_non_t.js:176:34
1188+
176| d4 as {|[string]: number, bar: number|};
1189+
^^^^^^ [1]
1190+
upper_non_t.js:170:26
1191+
170| const d4 = Diff4({bar: 3});
1192+
^ [2]
1193+
1194+
11191195

1120-
Found 72 errors
1196+
Found 76 errors
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function Diffs() {
149149
const d1 = Diff1({bar: 3});
150150
d1.foo as string;
151151
d1.bar as number;
152-
d1 as {|foo: string, bar: number|};
152+
d1 as {|foo: string, bar: number|}; // error T is inferred as {foo: string, bar: 3}
153153
d1 as {|foo: string | number, bar: number|}; // error
154154
d1.bad; // error
155155
d1 as empty; // error

0 commit comments

Comments
 (0)