If you have understood nodejs, you should be familiar with the following syntax:
Math. js
exports.add = function(n1, n2){return n1 + n2;}
Server. js
var math = require('./math.js');math.add(1,2);
In this way, you can import JS files in JS files. However, in web development, we usually need to import all JS files in order on the HTML page. Similar methods are also provided in Typescript.
Compoment. Ts
export class Compoment { private element: Element; private id: string; constructor (public config: Object) { } initialize() { } initCompoment() { }}
Panel. Ts
import mod = module("Compoment");class Panel extends mod.Compoment{ constructor (config) { super(config); console.log(this.config); }}
Next, use TSC panel during compilation. TS cannot achieve the desired effect. You need to use the amd module to compile the TSC -- module amd panel. TS and add require to the HTML page. JS and specify the entry.
<script data-main="panel" type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.1/require.min.js"></script>
Then we can test it in the browser.