I have some TypeScript files:
MyClass.ts
class MyClass {
constructor() {
}
}
export = MyClass;
MyFunc.ts
TypeScript 2.7 introduces support by emitting new helper methods: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#support-for-import-d-from-cjs-form-commonjs-modules-with---esmoduleinterop
So in tsconfig.json add these two settings:
{
// Enable support for importing CommonJS modules targeting es6 modules
"esModuleInterop": true,
// When using above interop will get missing default export error from type check since
// modules use "export =" instead of "export default", enable this to ignore errors.
"allowSyntheticDefaultImports": true
}
And now you can use:
import MyClass from './MyClass';