File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed
tests/baselines/reference Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -5092,7 +5092,14 @@ namespace ts {
5092
5092
// Handle export default expressions
5093
5093
if (isSourceFile(declaration)) {
5094
5094
const jsonSourceFile = cast(declaration, isJsonSourceFile);
5095
- return jsonSourceFile.statements.length ? checkExpression(jsonSourceFile.statements[0].expression) : emptyObjectType;
5095
+ if (!jsonSourceFile.statements.length) {
5096
+ return emptyObjectType;
5097
+ }
5098
+ const type = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
5099
+ if (type.flags & TypeFlags.Object) {
5100
+ return getRegularTypeOfObjectLiteral(type);
5101
+ }
5102
+ return type;
5096
5103
}
5097
5104
if (declaration.kind === SyntaxKind.ExportAssignment) {
5098
5105
return checkExpression((<ExportAssignment>declaration).expression);
Original file line number Diff line number Diff line change 1
1
/user.js(2,7): error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
2
+ /user.js(5,7): error TS2322: Type '{ "a": number; }' is not assignable to type '{ b: number; }'.
3
+ Property 'b' is missing in type '{ "a": number; }'.
2
4
/user.js(9,7): error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
3
5
/user.js(12,7): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
4
6
Property 'b' is missing in type '{ a: number; }'.
5
7
6
8
7
- ==== /user.js (3 errors) ====
9
+ ==== /user.js (4 errors) ====
8
10
const json0 = require("./json.json");
9
11
json0.b; // Error (good)
10
12
~
11
13
!!! error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
12
14
13
15
/** @type {{ b: number }} */
14
16
const json1 = require("./json.json"); // No error (bad)
17
+ ~~~~~
18
+ !!! error TS2322: Type '{ "a": number; }' is not assignable to type '{ b: number; }'.
19
+ !!! error TS2322: Property 'b' is missing in type '{ "a": number; }'.
15
20
json1.b; // No error (OK since that's the type annotation)
16
21
17
22
const js0 = require("./js.js");
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ import c = require('./c.json');
6
6
>c : (string | null)[]
7
7
8
8
import d = require('./d.json');
9
- >d : "dConfig"
9
+ >d : string
10
10
11
11
import e = require('./e.json');
12
- >e : -10
12
+ >e : number
13
13
14
14
import f = require('./f.json');
15
15
>f : number[]
@@ -64,14 +64,14 @@ const stringOrNumberOrNull: string | number | null = c[0];
64
64
>0 : 0
65
65
66
66
stringLiteral = d;
67
- >stringLiteral = d : "dConfig"
67
+ >stringLiteral = d : string
68
68
>stringLiteral : string
69
- >d : "dConfig"
69
+ >d : string
70
70
71
71
numberLiteral = e;
72
- >numberLiteral = e : -10
72
+ >numberLiteral = e : number
73
73
>numberLiteral : number
74
- >e : -10
74
+ >e : number
75
75
76
76
numberLiteral = f[0];
77
77
>numberLiteral = f[0] : number
You can’t perform that action at this time.
0 commit comments