我正在尝试使用内部模块将我的打字稿类分隔在单独的文件中。但是,main.ts 文件不会加载或识别子模块。
main.ts
/// <reference path="Car.ts" />
module Vehicles {
var c = new Vehicles.Car("red");
}
car.ts
module Vehicles {
export class Car {
color: string;
constructor(color: string) {
this.color = color;
console.log("created a new " + color + " car");
}
}
}
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"out": "everything.js main.ts car.ts"
}
}
Update:编辑 tsconfig 中的“out”标志,尝试将 main.ts 和 car.ts 编译到 everything.js - 这是不起作用的最后一部分:未创建 everything.js。相反,VS Code 创建了一个 main.js 和一个 car.js。似乎“out”标志被忽略了。我也尝试过“outFile”,结果相同。
main.ts
/// <reference path="car.ts" />
var c = new Car("red");
car.ts
class Car {
color: string;
constructor(color: string) {
this.color = color;
console.log("created a new " + color + " car");
}
}
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outFile": "main.js"
},
"files": [
"main.ts",
"car.ts"
]
}
任务.json
Kokodoko: 终于找到问题了!您必须省略“tasks.json”中的“args”选项,只有这样,参数才会出现
tsconfig.json 可以使用!我在这里找到了答案:
github.com/Microsoft/typescript/wiki/tsconfig.json。它说:当
输入文件在命令行上指定,tsconfig.json 文件是
被忽略
有关模块的更多信息,请不要忘记查看TypeScript 手册 http://www.typescriptlang.org/Handbook#modules-splitting-across-files
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)