Here is the repo for this question and if you want you can clone that repo, compile using TypeScript, and run it in node to see that there is a runtime error, but no compile time error.
To cut to the chase: why do I not get a compile time error by TypeScript in file1 when I try to run a method of an object imported from another module file2, given that the object has no methods?
This is the code, basically:
To set up the project:
mkdir test
cd test
npm init --yes
yarn add typescript
touch tsconfig.json
touch index.ts
touch jsModule.js
Here is tsconfig.json
:
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"sourceMap": true,
"target": "es2015",
"skipLibCheck": true,
"strict": true,
"resolveJsonModule": true
},
"exclude": ["node_modules"]
}
Here are the two files I created:
// jsModule.js
export const MyModuleObject = {};
// index.ts
import { MyModuleObject } from './jsModule';
console.log(MyModuleObject.method());
Problem: Typescript does not say anything about me calling MyModuleObject.method()