当前位置:网站首页>TypeScipt基础
TypeScipt基础
2022-06-11 17:16:00 【MW0309】
TypeScipt 介绍
- TypeScipt是由微软开发的一款开源的编程语言
- TypeScipt是JavaScript的超集,遵循最新的ES6,ES5规范。TypeScipt扩展了JavaScript的语法
- TyeScipt更像是java这样的面向对象语言,可以让js开发大型企业项目。
- 谷歌也在大力支持TypeScipt的推广,谷歌的Angular+就是基于TypeScipt的语法。
- 最新的vue React 也可以集成TypeScipt。
- Nodejs 框架Nostjs\midway中用的就是TypeScipt的语法。
TypeScript 为什么要为JS添加类型支持
背景:JS的类型系统存在 “先天缺陷”,JS代码中绝大部分错误都是类型错误 (Uncaught TypeError)
问题:增加了找Bug、改Bug 的时间,严重影响开发效率。
从编程语言的动静来区分,TypeScript属于静态类型的编程语言,J5属于动态类型的编程语言。
静态类型:编译期做类型检查;动态类型:执行期做类型检查。
代码编译和代码执行的顺序:1编译 2执行。
对于JS 来说:需要等到代码真正去执行的时候才能发现错误(晚)。
对于TS 来说:在代码编译的时候(代码执行前)就可以发现错误(早)。
并且,配合vsCode 等开发工具,TS可以提前到在编写代码的同时就发现代码中的错误,减少找 Bug、改Bug 时间。
TypeScript相比JS的优势
- 更早(写代码的同时)发现错误,减少找Bug、改 Bug 时间,提升开发效率。
- 程序中任何位置的代码都有代码提示,随时随地的安全感,增强了开发体验。
- 强大的类型系统提升了代码的可维护性,使得重构代码更加容易。
- 支持最新的ECMASCript 语法,优先体验最新的语法,让你走在前端技术的最前沿。
- TS 类型推断机制,不需要在代码中的每个地方都显示标注类型,让你在享受优势的同时,尽量降低了成本。
除此之外,vue了源码使用TS 重写、Angular默认支持 TS、React 与TS 完美配合,Typescript 已成为大中型前端项
TypeScipt 特点
TypeScript 主要有 3 大特点:
- 始于JavaScript,归于JavaScript
TypeScript 可以编译出纯净、 简洁的 JavaScript 代码,并且可以运行在任何浏览器上、Node.js 环境中和任何支持 ECMAScript 3(或更高版本)的JavaScript 引擎中。
- 强大的类型系统
类型系统允许 JavaScript 开发者在开发 JavaScript 应用程序时使用高效的开发工具和常用操作比如静态检查和代码重构。
- 先进的 JavaScript
TypeScript 提供最新的和不断发展的 JavaScript 特性,包括那些来自 2015 年的 ECMAScript 和未来的提案中的特性,比如异步功能和 Decorators,以帮助建立健壮的组件。
安装TypesScript
在使用npm命令之前电脑必须安装nodejs
安装
npm install -g typescript
简化运行TS的步骤
问题描述:每次修改代码后,都要重复执行两个命令,才能运行TS 代码,太繁琐。
简化方式:使用ts-node 包,直接在 Node.js 中执行TS 代码。
安装命令:npm i -g ts-node (ts-node 包提供了ts-node 命令)。
使用方式:ts-node hello.ts。
解释:ts-node 命令在内部偷偷的将TS->JS,然后,再运行JS代码。
边栏推荐
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- 04_ Feature engineering feature selection
- What problems are exposed when all Sohu employees are cheated?
- SQL injection attack under seed emulator (including SQL environment configuration)
- Pycharm使用小技巧 - 如何设置背景图片
- Katalon Studio Enterprise
- Is the second-class cost engineer worth the exam? What is the development prospect?
- QLineEdit 设置输入掩码
- 启牛推荐开通的股票账户安全吗?靠谱吗
- Custom or subscription? What is the future development trend of China's SaaS industry?
猜你喜欢

MATLAB中histogram函数的使用

二级造价工程师值得考吗?发展前景如何?

05_特征工程—降维

Global and China Mobile Network Optimization (MnO) industry development panoramic survey and Investment Strategy Research Report 2022-2028

vscode保存代碼時自動eslint格式化

AXI协议基础知识

10 times faster than 5g. Are you ready for 10 Gigabit communication?

LeetCode——42. Connected to rainwater (double pointer)

Real time myth -- real-time RTOS multitask performance analysis

Typescript learning notes (II)
随机推荐
05_特征工程—降维
Learning C language from scratch day 039
Classic reading of multi task learning: MMOE model
Message queue push / pull mode Learning & ActiveMQ and JMS learning
论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning
Bentley 使用 Authing 快速实现应用系统与身份的集成
Cocoapod only updates the specified library (does not update the index)
Derivation of child numbering formula for nodes numbered I in full k-ary tree
Docker安装mysql5.7(开启binlog功能、修改字符)
[Clickhouse column] create a new library, user and role
vscode保存代碼時自動eslint格式化
Oracle analysis function over and MySQL achieve similar effects
Elasitcsearch basic learning notes (1)
Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
SQL injection attack under seed emulator (including SQL environment configuration)
做跨境电商卖什么产品好?热销类目有哪些?
Recyclerview cache reuse analysis, source code interpretation
Custom or subscription? What is the future development trend of China's SaaS industry?
Solr (I) installation and permission control of Solr
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice