3. 为什么要使用Typescript? 优缺点是什么

本文探讨了在前端React项目中使用typescript的原因,强调了强类型检查、面向对象特性、智能感知、访问修饰符等优点,如减少错误、提供优秀的IDE支持及提前体验新JS特性。同时,也指出typescript存在的额外编码工作、第三方库兼容性问题及严格模式过于严格等挑战。
摘要由CSDN通过智能技术生成

这个项目的前端框架使用的是react,并且选择了typescript

为什么要使用typescript,给出了一些观点:

优点:

1. Strong typing:

所有的我们使用在我们client side 的 app都会有一个type。

所以我们的编译器会识别出如果我们使用了错误的type。

And our code editor or ide will recognize that if we make silly mistakes.

IDE 会直观的给出我们如果犯了错误,例如把一个string去赋值到一个number类型的变量。

For example, if we are trying to assign a string to a number, it's going to give us a warning in our IDE as we are typing the code. 

2. Objected oritented 

It's better than the pure script. 

3. Better intellisense 智能感知

如果你使用了面向对象在你的typescript中,我们会得到很好的智能感知和例如在ide中的自动填充功能。

If we use and create objects inside typescripte, we're going to get excellent intellisense and autocomplete in our code editor or IDE. 

4. Access modifiers

可以让一个类是private或者public。但实际上,任何typescript在最终编译的时候,都会转化为js,并且这些类的类型都会被移除。所以说其实在开发过程中能够起到最用而已。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值