In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 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 the function of TypeScript 1.6, I believe that 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!
Microsoft has released TypeScript, an open source language that can run on Node.js. As a superset of JavaScript, TypeScript adds optional static types and class-based object-oriented programming while being compatible with JavaScript, and can be used for the development of large-scale JavaScript applications. As soon as TypeScript is launched, it has received wide attention and has been gradually accepted by many users. Microsoft also listens to the feedback of the majority of users and constantly updates TypeScript. Recently, Microsoft updated TypeScript again and launched version 1.6. This release adds support for React/JSX, class expressions, and many new features.
First of all, Microsoft's TypeScript team listened fully to the feedback from React experts and teams. Therefore, the new version of TypeScript fully supports React and JSX. MSDN gives an example of a document of type tsx. The code in this document is as follows.
Class MyClass extends React.Component {render () {Hello, {this.props.who};} props: {who?: string;}} var x =
In this example, TypeScript code and JSX syntax coexist perfectly, making it easy for React developers to use the Typescript language. In this way, users can develop React and JSX when using VS, VS Code or Sublime.
In addition, the new version of TypeScript adds support for class expressions. As shown in the following example, this feature allows developers to define classes based on requirements when using expressions.
Class StateHandler extends class {reset () {return true;}} {constructor () {super ();}} var g = new StateHandler (); g.reset ()
In previous versions, developers could use if statements to narrow down the types of variables. The new version of TypeScript takes into account the needs of the majority of users and directly increases the support of user-defined daemon functions.
Interface Animal {name: string;} interface Cat extends Animal {meow ();} function isCat (a: Animal): an isCat {return a.name = 'kitty';} var x: Animal;if (isCat (x)) {x.meow (); / / OK, x isCat in this block}
The daemon function takes "an is X" as the flag and returns a Boolean or other value based on the user definition. This feature allows not only typeof and instanceof checking, but also interfaces and customized analysis.
To better support mixing between different types and to extend existing classes, TypeScript version 1.6 also adds a new type operator'&'. The biggest highlight of this operator is its support for generics.
Function extend (first: t, second: U): t & U {let result = {}; for (let id in first) {result [id] = first [id];} for (let id in second) {if (! result.hasOwnProperty (id)) {result [id] = second [id];} return result;} var x = extend ({a: "hello"}, {b: 42}); x.a; / / worksx.b; / / works
Previously, many users had wanted TypeScript to support abstract classes. Now, the new version finally adds support for abstract classes.
Abstract class A {foo (): number {return this.bar ();} abstract bar (): number;} var a = new A (); / / error, Cannot create an instance of the abstract class' A'class B extends A {bar () {return 1;}} var b = new b (); / / success, all abstracts are defined
The category name is also a feature already supported in previous versions of TypeScript. However, the previous category name is strictly limited to use-- it can only be used for certain classes. The new version of TypeScript extends this functionality and begins to support generic aliases.
Type switcharoo= (u: U, tbob T) = > Tinto var f: switcharoo;f ("bob", 4). This is all the content of this article "what is the function of TypeScript 1.6". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.