Skip to content

Instantly share code, notes, and snippets.

@ryancat
Last active October 22, 2018 06:35
Show Gist options
  • Select an option

  • Save ryancat/a3266643a1ffae170ff456340ae62112 to your computer and use it in GitHub Desktop.

Select an option

Save ryancat/a3266643a1ffae170ff456340ae62112 to your computer and use it in GitHub Desktop.
typescript migration demo
// typescript will give error: An import path cannot end with a '.ts' extension.
// this is just for clarification purpose!
import { IModuleAConfig } from './types.ts';
import * as ModuleAPrototype from './ModuleAPrototype.js';
class ModuleA {
constructor(config: IModuleAConfig) {
this.initModuleA(config);
}
// Need to add this to by pass typescript check
// Will be overwritten by ModuleAPrototype
private initModuleA(config: IModuleAConfig): void {}
}
Object.assign(ModuleA.prototype, ModuleAPrototype);
// Use export = ModuleA so that the CommonJS require function
// still works as before.
export = ModuleA;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment