Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在TypeScript中使用systemjs导入和导出模块?_Typescript_Systemjs - Fatal编程技术网

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

如何在TypeScript中使用systemjs导入和导出模块?,typescript,systemjs,Typescript,Systemjs,有人知道如何在TypeScript中使用systemjs导出模块吗?我收到错误:TS1148无法编译模块,除非提供了“--module”标志 这是我的密码; 动物实验 export class Animal { color: string; age: number; constructor(color: string, age:number) { this.color = color; this.age = age; }

有人知道如何在TypeScript中使用systemjs导出模块吗?我收到错误:
TS1148无法编译模块,除非提供了“--module”标志

这是我的密码; 动物实验

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);
    }
}
狗狗

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);

您可以在系统配置中指定typescript编译器选项。我们可以找到很多选择


谢谢我在tsconfig.json“compilerOptions”中添加了以下代码:{“target”:“ES5”,“module”:“system”}然后它就可以工作了。但随后出现了另一个错误:系统未定义。你知道怎么解决吗?我是否需要在html文件中同时包含animal.js和dog.js文件?我是打字新手。你知道有什么好的资源可以帮助我使用TypeScript和systemjs吗?似乎大多数网站都使用nodejs导入模块,我想知道使用systemjs导入模块的好处是什么?谢谢。浏览器无法导入模块,这就是SystemJS、webpack、browserify、requirejs等存在的原因。我建议您阅读有关SystemJS回购协议的文档。您可能忘记了html中系统的
标记,并且没有为编译的.js文件添加
标记。系统将为您注入它们。
System.config({
    typescriptOptions:{
        module: 'system'
    }
});