我正在尝试学习打字稿和angular.I写代码
**main.ts**
import { LikeComponent } from "./like.component";
let component = new LikeComponent(10,true);
component.onClick();
console.log(`likescount: ${component.likesCount}, isSelect: ${component.isSelected}`);
**like.component.ts**
export class LikeComponent
{
constructor(public likesCount: number,public isSelected: boolean) {
}
onClick() {
this.likesCount += (this.isSelected) ? 1: -1;
this.isSelected = !this.isSelected;
}
}
我有类似的文件夹结构,
我尝试在tsconfig.js中添加以下代码,但没有运气
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
我试图仅运行'tsc like.component.cs',但出现了类似'除非提供了模块,否则无法运行外部模块'的错误。
tsc --version:1.0.3.0
答案 0 :(得分:0)
请升级TypeScript。我无法找到您的确切版本1.0.3.0,但是我尝试了4年的版本1.0.0.0(在npm上为1.0.0),并且遇到了相同的错误。 TypeScript 3.0.3可以毫无问题地编译代码。