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
|
/user.js(2,7): error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
/user.js(5,7): error TS2741: Property 'b' is missing in type '{ "a": number; }' but required in type '{ b: number; }'.
/user.js(9,7): error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
/user.js(12,7): error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type '{ b: number; }'.
==== /user.js (4 errors) ====
const json0 = require("./json.json");
json0.b; // Error (good)
~
!!! error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
/** @type {{ b: number }} */
const json1 = require("./json.json"); // No error (bad)
~~~~~
!!! error TS2741: Property 'b' is missing in type '{ "a": number; }' but required in type '{ b: number; }'.
!!! related TS2728 /user.js:4:14: 'b' is declared here.
json1.b; // No error (OK since that's the type annotation)
const js0 = require("./js.js");
json0.b; // Error (good)
~
!!! error TS2339: Property 'b' does not exist on type '{ "a": number; }'.
/** @type {{ b: number }} */
const js1 = require("./js.js"); // Error (good)
~~~
!!! error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type '{ b: number; }'.
!!! related TS2728 /user.js:11:14: 'b' is declared here.
js1.b;
==== /json.json (0 errors) ====
{ "a": 0 }
==== /js.js (0 errors) ====
module.exports = { a: 0 };
|