Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the new features of TypeScript4.0

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use the new features of TypeScript4.0". In daily operation, I believe many people have doubts about how to use the new functions of TypeScript4.0. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the new features of TypeScript4.0". Next, please follow the editor to study!

The main updates of version 4.0 are as follows:

Variable parameter tuple type

Marked tuple elements

Class attribute inference of constructor

Short circuit allocation operator

Unknown in catch clause

Customized JSX factory

Speed increase in build mode with-noEmitOnError parameters

-incremental with-noEmit

Editor improvement

Convert to optional link

Support / * * @ deprecated * /

Partial editing mode at startup

Smarter automatic import

Breaking Changes

Class attribute inference of constructor

When noImplicitAny is enabled, TypeScript 4.0 can now use control flow parsing (control flow analysis) to determine the type of attributes in the class.

Class Square {/ / Previously: implicit any! / / Now: inferred to `number`! Area; sideLength; constructor (sideLength: number) {this.sideLength = sideLength; this.area = sideLength * * 2;}}

If not all paths to the constructor are assigned to instance members, this property may be considered undefined.

Class Square {sideLength; constructor (sideLength: number) {if (Math.random ()) {this.sideLength = sideLength;}} get area () {return this.sideLength * * 2; / ~ / / error! Object is possibly 'undefined'. }}

In clearer cases (such as having some kind of initialize method), explicit type comments and fixed assignment assertions (!) may be required if you are in strictPropertyInitialization.

Class Square {/ / definite assignment assertion / / v sidelighting: number; / / ^ / / type annotation constructor (sideLength: number) {this.initialize (sideLength)} initialize (sideLength: number) {this.sideLength = sideLength;} get area () {return this.sideLength * * 2;}} short circuit allocation operator

JavaScript and many other languages support compound assignment operators. The compound assignment operator applies an operator to two parameters, and then assigns the result to the left. As follows:

/ Addition// a = a + ba + = bba ba / Subtraction// a = a-ba-= bumbago / Multiplication// a = a * ba * = baptism / Division// a = a / ba / = Exponentiation// a = a * * ba * * = bbot / Left Bit Shift// a = a

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report