HelloTypeScript
TypeScript:
微软推出,JavaScript超集
TypeScript:
Vue React NG
Type:类型
function add(a:number,b:number){
return a+b;
}
add(10,20);
add(10,"20"); // 报错
面向对象
class interface extends
ES5 -> prototype function object
规避一些bug问题
类型错误:
js:执行的时候发生错误
ts:编译的时候就已经发生了错误
打开控制台,输入
npm install -g typescript
再输入tsc发现不报错,表示安装成功
如何避免这样的重复输入? 只需在命令行输入tsc -w hello.ts
比如在hello.ts 里把30 改成300,hello.js中相应的部分也会动态的跟着改变
这样就可以实时监听到所有代码的修改