当前位置:网站首页>【TypeScript】Why choose TypeScript?
【TypeScript】Why choose TypeScript?
2022-08-03 10:53:00 【Ji Shuaizhen's web log】
Self-introduction: Hello everyone, my name is Ji Shuaizhen's network log (the account name is the same on other platforms), Internet front-end development engineer, worked for 5 years, went to Shanghai and Beijing, experienced startups, joined the Ali local life team, and nowZhengzhou Beiyou Education is engaged in programming training.
I. Introduction
TypeScript is essentially the same as JavaScript. You can understand TypeScipt as a JavaScript with type annotations, such as const num = 1, which conforms to both TypeScript and JavaScript syntax.In addition, TypeScript is an intermediate language, and ultimately it needs to be translated into pure JavaScript, and then handed over to various terminals for interpretation and execution.However, TypeScript will not destroy the existing knowledge system of JavaScript, because it does not create a new syntax that is completely different from JavaScript, it is still a "familiar recipe" and "familiar flavor".
Second, TypeScript is more reliable
After the introduction of TypeScript into business applications, when we received an alarm from Sentry (an open source front-end error monitoring system), about "'undefined' is not a function" and "Cannot read property 'xx' of null|undefined"Low-level error stats like this are largely absent.And this is thanks to the static type detection of TypeScript, so that at least 10% of JavaScript errors (mainly some low-level errors) can be found and solved during the development phase.Before any operator, TypeScript can detect whether the received type (when the code is running, the operator receives the actual data; when static detection, the operator receives the type) is supported by the current operator.
When TypeScript type detection capabilities cover the entire file, the entire project code, any changes that break the contract can be automatically detected (even across multiple files, many passes), and type errors are raised.Therefore, you can safely modify and refactor business logic without worrying too much about making low-level mistakes due to ill-consideration.
When taking over a complex and large-scale application, TypeScript can make the application easy to maintain, iterative, stable and reliable, and it will also make you feel more secure.
Three, interface-oriented programming
The essence of writing TypeScript type annotations is interface design.An example of a React component designed to display user information using TypeScript, from which we can understand the structure and type of data received by the component at a glance, and clearly know how to write safe and stable JSX code inside the component.
interface IUserInfo {/** user id */id: number;/** username */name: string;/** avatar */avatar?: string;}function UserInfo(props: IUserInfo) {...}TypeScript has the potential to change the way you think, making it a good habit over time.For example, before writing specific logic, we need to design the data structure, write type annotations, and implement business logic according to this interface convention.This can obviously reduce unnecessary code refactoring, thereby greatly improving coding efficiency.At the same time, you will better understand the importance of interface conventions, and you will also constrain yourself/others to design interfaces, write annotations, and abide by conventions.
Fourth, TypeScript is becoming mainstream
Compared to the rival Facebook's Flow, TypeScript has the advantage of type programming, and it is also endorsed by two international companies, Microsoft and Google.In addition, more and more mainstream frameworks (such as React, Vue 3, Angular, Deno, Nest.js, etc.) either choose TypeScript to write source code, or provide perfect support for TypeScript.With the popularity of TypeScript, TypeScript has become a mainstream technical direction in China (domestic lags behind foreign countries). Major domestic Internet companies and small and medium-sized teams have begun to try to use TypeScript to develop projects, and more and more people are learning and using it.it.
V. Summary
Proficient in TypeScript, you can easily win offers from big manufacturers.
边栏推荐
猜你喜欢
随机推荐
Web Server 设置缓存响应字段的一些推荐方案
多态详细讲解(简单实现买票系统模拟,覆盖/重定义,多态原理,虚表)
Apache Doris系列之:数据模型
干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
_GLIBCXX_USE_CXX11_ABI 宏的作用
玉溪卷烟厂通过正确选择时序数据库 轻松应对超万亿行数据
error C2872: “flann”: 不明确的符号 解决方法
微信多开批处理(自动获取安装路径)
ScrollView嵌套RecyclerView滚动冲突
LeetCode_多叉树_中等_429.N 叉树的层序遍历
自定义实现乘风破浪的小船
浪潮—英伟达打造元宇宙新方案,虚拟人的故事将再破你的认知
程序员架构修炼之道:如何设计出可持续演进的系统架构?
build --repot
如何将Oracle/MySQL中的数据迁移到GBase 8c中?
[华为云在线课程][SQL语法入门][学习笔记]
Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)
HCIP第十七天笔记
oracle计算同、环比
MATLAB程序设计与应用 2.7 结构数据与单元数据









