Last active
October 22, 2018 06:35
-
-
Save ryancat/a3266643a1ffae170ff456340ae62112 to your computer and use it in GitHub Desktop.
typescript migration demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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