File tree Expand file tree Collapse file tree
tests/baselines/reference Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5092,7 +5092,14 @@ namespace ts {
50925092 // Handle export default expressions
50935093 if (isSourceFile(declaration)) {
50945094 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;
50965103 }
50975104 if (declaration.kind === SyntaxKind.ExportAssignment) {
50985105 return checkExpression((<ExportAssignment>declaration).expression);
Original file line number Diff line number Diff line change 11/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; }'.
24/user.js(9,7): error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
35/user.js(12,7): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
46 Property 'b' is missing in type '{ a: number; }'.
57
68
7- ==== /user.js (3 errors) ====
9+ ==== /user.js (4 errors) ====
810 const json0 = require("./json.json");
911 json0.b; // Error (good)
1012 ~
1113!!! error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
1214
1315 /** @type {{ b: number }} */
1416 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; }'.
1520 json1.b; // No error (OK since that's the type annotation)
1621
1722 const js0 = require("./js.js");
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ import c = require('./c.json');
66>c : (string | null)[]
77
88import d = require('./d.json');
9- >d : "dConfig"
9+ >d : string
1010
1111import e = require('./e.json');
12- >e : -10
12+ >e : number
1313
1414import f = require('./f.json');
1515>f : number[]
@@ -64,14 +64,14 @@ const stringOrNumberOrNull: string | number | null = c[0];
6464>0 : 0
6565
6666stringLiteral = d;
67- >stringLiteral = d : "dConfig"
67+ >stringLiteral = d : string
6868>stringLiteral : string
69- >d : "dConfig"
69+ >d : string
7070
7171numberLiteral = e;
72- >numberLiteral = e : -10
72+ >numberLiteral = e : number
7373>numberLiteral : number
74- >e : -10
74+ >e : number
7575
7676numberLiteral = f[0];
7777>numberLiteral = f[0] : number
You can’t perform that action at this time.
0 commit comments