当前位置:网站首页>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代码。
边栏推荐
- 04_ Feature engineering feature selection
- mysql 大表的拆分方式
- 信息安全数学基础 Chapter 3——有限域(二)
- Global and Chinese molten carbonate fuel cell industry outlook and market panoramic Research Report 2022-2028
- 05_特征工程—降维
- LeetCode-1005. K 次取反后最大化的数组和
- Leetcode-- array
- Oracle analysis function over and MySQL achieve similar effects
- Kernel density estimation (2D, 3D)
- Analyze which should be tested in PMP and ACP with actual cases? Which is more useful?
猜你喜欢

Qlineedit set input mask

04_特征工程—特征选择

Authing 双周动态:应用市场上线(5 .10 —5 .22 )

Guide to Dama data management knowledge system: percentage of chapter scores

How to become an optimist organization?

Vscode automatic eslint formatting when saving code

Axi protocol Basics

AXI协议基础知识

vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“

Analysis report on sales status and supply and demand prospects of phosphoric acid fuel cell industry in the world and China 2022-2028 Edition
随机推荐
05_特征工程—降维
How to become an optimist organization?
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
Weekly recommended short video: rookie CEO talks about the new logistics track in the future
Activity | authing's first channel cooperation activity came to a successful conclusion
Pychart tips - how to set up a background picture
threejs中设置物体的贴图+场景的6面贴图 +创建空间
论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning
Association relationship
What subclasses inherit, polymorphism, and upward transformation
Connection and difference of network streaming media protocol (RTP RTCP RTMP HLS)
一套ThinkPHP微信小程序商城源码带后台管理
Cs0006 C failed to find metadata file "c:\users\... Problem
Connect the server with springboard / fortress through xshell
05_ Feature Engineering - dimension reduction
MATLAB中histogram函数的使用
RecyclerView缓存复用解析,源码解读
^31 prototype interview questions
信息安全数学基础 Chapter 4——二次剩余与方根
做跨境电商卖什么产品好?热销类目有哪些?