Naming of TypeScript's union and intersection types

后端 未结 6 1077
忘掉有多难
忘掉有多难 2020-12-04 12:25

I can\'t understand the logic behind the terms union types and intersection types in TypeScript.

Pragmatically, if the properties of different type

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 12:46

    The type A | B refers to objects which are either A or B. In other words, values of such type are drawn from the union of values for A and values for B.

    The type A & B refers to objects which are both A and B. In other words, values of such type are drawn from the intersection of values for A and values for B.

    The naming and semantics are identical in other languages such as C++.

提交回复
热议问题