VSCode 中的打字稿适用于您的示例。
在 VSCode 中创建一个新文件夹
使用编译器选项创建一个简单的 tsconfig.json 文件
{
"compilerOptions": {
"target": "ES3",
"module": "amd",
"sourceMap": false
}
}
在 app.ts 中创建示例代码
export interface IPerson {
firstName: string;
lastName: string;
}
export class Person implements IPerson {
constructor(public firstName: string, public lastName: string) {
var module = angular.module("myApp", []);
}
}
重要提示:使用来自definitelyTyped的DefinitelyTyped tsd
命令
。Angular 依赖于 jQuery。$tsd install angular jquery --save
添加tsd.d.ts
文件引用到app.ts
/// <reference path="typings/tsd.d.ts" />
.settings/tasks.json
使用shift++在应用程序目录中配置一个Task Runner,ctl然后b选择“Configure Task Runner”。删除内容"args:[Hello World],
或创建新的类似任务"args:[],
shift使用+ ctl+使用 Task Runner 编译b
这是我使用的未注释任务运行器"args": [],
// A task runner that calls the Typescipt compiler (tsc) and
// Compiles a app.ts program
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the app.ts program to compile.
"args": [],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
如果在 VSCode 中编译仍然存在问题,请尝试从项目目录中的命令行获取线索。
tsc --module amd --out app.js app.ts
并如前所述检查您的版本:
02:00:23 ツ gjsmith3rd@DV7:~/Workspaces/Examples/TypeScript/MSDN/MyProject5 >tsc --version
message TS6029: Version 1.5.3
考虑将 tsc 更新到最新版本,在此编辑时为 v1.5.3,带有sudo npm install tsc -g
.