TS 学习笔记 1
安装
- vscode 安装,code.visualstudio.com
- node.js 安装, nodejs.org
- 借助npm 安装 tsc, npm i -g tsc
- 终端执行tsc,权限修改,set-ExecutionPolicy RemoteSigned
- 配置编译,这样就不用每次都tsc index.ts 了;tsc --init ; 便会生成tsconfig.json
- 安装包 ts-node ;
示例
var userName: string = "kyriewang"
var userId: number = 1
var isShow: boolean = false
isShow = true
var unType: undefined = undefined
var nullType: null = null
var arr: string[] = []
arr.push("kyriewang")
let typeArr: [string, number]
typeArr = ["kyriewang", 18]
enum typeS {
typeString,
typeNumber,
typeNull
}
var typeStr: any;
let vTs: void;
vTs = undefined;
var func: Function = () => { }
func = function name(params: number) {
}
console.log("hello");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TypeScript</title>
</head>
<body>
<script src="index.js">
</script>
</body>
</html>
|