如何在vscode 中配置:TypeScript开发node环境
来源:互联网 发布:软件需求分析报告 编辑:程序博客网 时间:2024/06/02 04:24
配置项目
创建package.json
建一个目录的文件夹,起一个你喜欢的名字。
node项目嘛,当然要先建立一个package.json
1
npm init
跟着提示下一步就好了。
创建 tsconfig.json
typescript 的项目都需要一个tsconfig.json
1
tsc --init
会创建一个这样内容的tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
{
"compilerOptions"
: {
"module"
:
"commonjs"
,
"target"
:
"es5"
,
"noImplicitAny"
:
false
,
"sourceMap"
:
false
},
"exclude"
: [
"node_modules"
]
}
因为写node.js你可以修改tagget为es6, 要调试把 sourceMap改为true, 添加allowjs为true,就可以ts和js混合玩了.
1
2
3
4
5
6
7
8
9
10
11
12
{
"compilerOptions"
: {
"module"
:
"commonjs"
,
"target"
:
"es6"
,
"noImplicitAny"
:
false
,
"sourceMap"
:
true
,
"allowJs"
:
true
},
"exclude"
: [
"node_modules"
]
}
安装 node 的 .d.ts 库
还是因为是node.js开发,我们要安装node的ts库, 为了强类型,主要还是为了智能感知。
1
typings install dt~node --global
国内的用typings 的时候,而且就会抽风,好久都完成不了,不要紧,Ctrl+C掉了,再执行,多试几次,总会有成功的时候的。
配置 vscode
打开 vscode
1
code .
windows话 也可以右键菜单,open with Code.
配置 TypeScript 编译
按ctrl + shift + b, 如果没有配置过,task, 就会在上面提示。
选择【配置任务运行程序】
会在.vscode文件夹下生成一个 task.json, 基本不用动,我到现在是没有改过它。
1
2
3
4
5
6
7
8
9
10
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version"
:
"0.1.0"
,
"command"
:
"tsc"
,
"isShellCommand"
:
true
,
"args"
: [
"-p"
,
"."
],
"showOutput"
:
"silent"
,
"problemMatcher"
:
"$tsc"
}
小试身手
我们来创建一个app.ts 文件,随便写点东西吧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* person
*/
class
person {
constructor() {
}
/**
* print
*/
public
print() {
console.log(
'this is a person'
)
}
}
let p =
new
person();
p.print();
按Ctrl+Shift+B,编译一下,就会生成一个app.js.
现在运行试试结果吧。
转:http://www.2cto.com/kf/201606/521390.html
0 0
- 如何在vscode 中配置:TypeScript开发node环境
- 【学习笔记】在VSCode上配置typescript + nodejs 开发环境
- 如何在vscode配置php开发环境
- 使用VsCode + Node.js搭建TypeScript开发环境
- 如何在VSCode中配置python环境
- VScode搭建TypeScript开发环境
- 如何在VScode中配置Python的交互式环境
- vscode开发nodejs配置备忘录(typescript)
- vscode中配置golang开发环境
- vscode开发Typescript笔记
- 在VSCODE 调试 NODE.js 部署环境
- vscode 配置go开发环境
- (转)Rust: 在vscode配置 Rust 开发环境
- 用vscode创建typescript的node工程
- 使用Typescript开发node.js项目——简单的环境配置
- vscode 配置 go 语言开发环境
- ubuntu 16.04 VSCode 配置C++开发环境
- React + Typescript + Webpack 开发环境配置
- Sphinx安装配置应用
- Android 7.0 ActivityManagerService(8) 进程管理相关流程分析(2) updateOomAdjLocked
- WebService入门
- 用Maven创建web项目(详细步骤)
- Makefile
- 如何在vscode 中配置:TypeScript开发node环境
- RBD 导出一个image
- ZCMU—1198
- iOS NSLocalizedString
- android 使用递归遍历文件
- jstack和线程dump分析
- 事务的四个特性
- Apache 负载多个项目
- <Java设计模式>—UML类图