如何在 TypeScript 中使用 systemjs 导入和导出模块?

How to import and export module using systemjs in TypeScript?

有谁知道如何在 TypeScript 中使用 systemjs 导出模块?我收到错误:TS1148 cannot compile modules unless the '--module' flag is provided.

这是我的代码; animal.ts

export class Animal {
    color: string;
    age: number;

    constructor(color: string, age:number) {
        this.color = color;
        this.age = age;
    }

    add(animal: Animal) {
        return new Animal(this.color + animal.color, this.age + animal.age);
    }
}

dog.ts

import {Animal} from './animal';

var animal1 = new Animal("red", 1);
var animal2 = new Animal("yellow", 2);
var animal3 = animal1.add(animal2);
console.log('Combine Two Animals' + animal3);

您可以在系统配置中指定您的打字稿编译器选项。可以找到很多选项here

System.config({
    typescriptOptions:{
        module: 'system'
    }
});