In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the most common statements in TS merge, 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!
Foreword:
The most common declarative merge in TS: interface merge
Before we talk about interface consolidation, let's talk about declaring a merger.
Declare merge:
What is a declared merger?
In fact, it is easy to understand that the declaration merge in TS means that the compiler will merge the declaration of the same name into one declaration.
Results of the merger:
The merged declaration will have the properties of two or more previous declarations at the same time.
Question:
What do these two or more specifically refer to?
In fact, in terms of scores, what we are going to talk about today is one of them. The simplest and most common type of declaration merge is interface merge.
1. Merge interface
As we just said, "the merged declaration will have the characteristics of the original two or more declarations at the same time."
The same is true for the merger of interfaces, which puts members of both sides into an interface with the same name
It should be noted that the members in the interface have function members and non-function members, and the situation is different.
1.1 non-function member
For example:
Interface Box {height: number;} interface Box {width: number;} let box: Box = {height: 2, width: 3}
In the above code, two interfaces with the same name are defined (in actual development, they may come from different files), and eventually the contents will be mixed together.
However, it should be noted that the members in the above cases are unique, but if non-function members with the same name are declared in both interfaces and their types are different, the compiler will report an error.
1.2 function members
For the function members in it, each function declaration with the same name is treated as an overload of the function. And when interface An is merged with the later interface A, the latter interface has a higher priority.
For example, the official example:
Interface Cloner {clone (animal: Animal): Animal;} interface Cloner {clone (animal: Sheep): Sheep;} interface Cloner {clone (animal: Dog): Dog; clone (animal: Cat): Cat;}
It will eventually be merged into a single declaration, as follows:
Interface Cloner {clone (animal: Dog): Dog; clone (animal: Cat): Cat; clone (animal: Sheep): Sheep; clone (animal: Animal): Animal;}
There are two points to note:
The order of declarations in each set of interfaces remains the same.
The order between the groups of interfaces is that later interface overloads appear in the front position.
However, there are exceptions: when a special function signature appears. If there is a parameter in the signature whose type is a single string literal (for example, a union type that is not a string literal), it will be promoted to the top of the overloaded list.
The above is all the contents of the article "what are the most common statements in TS?" 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.