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

What are the improvements in TypeScript 2.7?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you what improvements TypeScript 2.7 has, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

TypeScript 2.7 introduced some groundbreaking changes that developers should be aware of when upgrading their code base to use TypeScript 2.7.

When asked about the current release plan for TypeScript, project manager Daniel Rosenwasser said:

I think in the broadest sense, we focus on ease of use and make sure that our existing users continue to invest in TypeScript. The former usually reduces the learning cost at the beginning, while the latter usually focuses on performance and safety.

For example, existing TypeScript users require stricter checks on class initialization. After TypeScript 2.6 added strict function type checking, version 2.7 added strict property initialization checks that use the strictPropertyInitialization flag in the class. This flag examines the properties of each instance of the class to determine whether it is initialized in the constructor of the class or through the property initializer. When upgraded to 2.7, developers who use strict tags will automatically get this additional check in their source code. It is recommended that you use this strict tag in TypeScript because it helps developers find and eliminate other types of error or abnormal behavior.

The explicit assignment assertion function is also available, and even when the TypeScript parser cannot confirm the assignment, it can instruct TypeScript's control flow analyzer to always recognize an explicitly assigned.

According to Anders Hejlsberg, one of the designers of TypeScript, the version also improves the type inference of the literals of objects:

Improves type inference of literal quantities of multiple objects that appear in the same context. When multiple object literal types form a union type, we normalize the object literal type so that all attributes appear in each component of the union type.

Const obj = test? {text: "hello"}: {}

/ / {text: string} | {text?: undefined} const s = obj.text; / / string | undefined

In the first line we infer the type of obj {}, and the second line then causes an error because obj does not seem to have attributes. This is obviously not the ideal effect.

Other language-level improvements include improved handling of structurally similar union types and instanceof expressions, and better type protection inferred from operators.

TypeScript 2.7also provides improved support for ES2015+ symbols. Attributes can be named using symbols declared by const, and Identifier or PropertyAccessExpression can be used as part of the calculated attribute name in the interface, class, or type text.

Improved interoperability with CommonJS modules, support for import d from "cjs", and use of the esModuleInterop flag. Internally, TypeScript leverages the ES module of the CJS module. Rosenwasser explained to InfoQ the motivation behind this feature:

We know that there is some unfriendliness in the module interoperability strategy, which makes it more difficult for some users to master TypeScript. This is an obstacle for new TypeScript users, which is why we want to increase the priority of esModuleInterop tags in this release. Of course, we are also involved in updating ECMAScript standards, and we pay great attention to absorbing these standards as we develop our language.

The third phase of the digital separator proposal, expected to be part of ES2018, is now included in TypeScript to help TypeScript maintain its current annual update to the JavaScript language.

In TypeScript 2.7, there are some improvements for the developer experience. Development tools like webpack and Gulp will benefit from the new incremental build compiler API. This change will make it easier for the tool to update the resources brought about by the updated code, rather than having to rebuild the entire project in each incremental update. In addition, ide provides an updated TypeScript language service, API, that allows developers to automatically fix all identified problems in files.

TypeScript 2.7can be installed through npm's npm install-g typescript command, or can be obtained through GitHub.

These are all the contents of this article entitled "what are the improvements in TypeScript 2.7.Thank you for reading!" I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Internet Technology

Wechat

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

12
Report