-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intersection types #3622
Intersection types #3622
Changes from 3 commits
643832d
d2955e8
d571034
529fcfd
c623e6c
1858810
90ffdf7
a13b642
c517a63
6ae775b
fb1bf42
30d15a8
144a635
fc1888e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,7 @@ namespace ts { | |
ArrayType, | ||
TupleType, | ||
UnionType, | ||
IntersectionType, | ||
ParenthesizedType, | ||
// Binding patterns | ||
ObjectBindingPattern, | ||
|
@@ -634,10 +635,14 @@ namespace ts { | |
elementTypes: NodeArray<TypeNode>; | ||
} | ||
|
||
export interface UnionTypeNode extends TypeNode { | ||
export interface UnionOrIntersectionTypeNode extends TypeNode { | ||
types: NodeArray<TypeNode>; | ||
} | ||
|
||
export interface UnionTypeNode extends UnionOrIntersectionTypeNode { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add brands so that these UnionTypeNode and IntersectionTypeNode are distinguished and not assignable to each other. |
||
|
||
export interface IntersectionTypeNode extends UnionOrIntersectionTypeNode { } | ||
|
||
export interface ParenthesizedTypeNode extends TypeNode { | ||
type: TypeNode; | ||
} | ||
|
@@ -1479,7 +1484,7 @@ namespace ts { | |
Merged = 0x02000000, // Merged symbol (created during program binding) | ||
Transient = 0x04000000, // Transient symbol (created during type check) | ||
Prototype = 0x08000000, // Prototype property (no source representation) | ||
UnionProperty = 0x10000000, // Property in union type | ||
SyntheticProperty = 0x10000000, // Property in union or intersection type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we use "UnionOrIntersection" elsewhere. It seems like another place we'd want to use them. i.e. "UnionOrIntersectionProperty". "Synthetic" is odd, as it's a term we don't use consistently for this concept elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with @CyrusNajmabadi. After reading the code, it will be much easier to read if it is name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, also instantiated properties are just as synthetic as union/intersection properties. |
||
Optional = 0x20000000, // Optional property | ||
ExportStar = 0x40000000, // Export * declaration | ||
|
||
|
@@ -1558,7 +1563,7 @@ namespace ts { | |
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic) | ||
mapper?: TypeMapper; // Type mapper for instantiation alias | ||
referenced?: boolean; // True if alias symbol has been referenced as a value | ||
unionType?: UnionType; // Containing union type for union property | ||
containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. align comments. |
||
resolvedExports?: SymbolTable; // Resolved exports of module | ||
exportsChecked?: boolean; // True if exports of external module have been checked | ||
isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration | ||
|
@@ -1620,17 +1625,18 @@ namespace ts { | |
Interface = 0x00000800, // Interface | ||
Reference = 0x00001000, // Generic type reference | ||
Tuple = 0x00002000, // Tuple | ||
Union = 0x00004000, // Union | ||
Anonymous = 0x00008000, // Anonymous | ||
Instantiated = 0x00010000, // Instantiated anonymous type | ||
Union = 0x00004000, // Union (T | U) | ||
Intersection = 0x00008000, // Intersection (T & U) | ||
Anonymous = 0x00010000, // Anonymous | ||
Instantiated = 0x00020000, // Instantiated anonymous type | ||
/* @internal */ | ||
FromSignature = 0x00020000, // Created for signature assignment check | ||
ObjectLiteral = 0x00040000, // Originates in an object literal | ||
FromSignature = 0x00040000, // Created for signature assignment check | ||
ObjectLiteral = 0x00080000, // Originates in an object literal | ||
/* @internal */ | ||
ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type | ||
ContainsUndefinedOrNull = 0x00100000, // Type is or contains Undefined or Null type | ||
/* @internal */ | ||
ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type | ||
ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6 | ||
ContainsObjectLiteral = 0x00200000, // Type is or contains object literal type | ||
ESSymbol = 0x00400000, // Type of symbol primitive introduced in ES6 | ||
|
||
/* @internal */ | ||
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, | ||
|
@@ -1639,6 +1645,8 @@ namespace ts { | |
StringLike = String | StringLiteral, | ||
NumberLike = Number | Enum, | ||
ObjectType = Class | Interface | Reference | Tuple | Anonymous, | ||
UnionOrIntersection = Union | Intersection, | ||
StructuredType = ObjectType | Union | Intersection, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment explaining why these are considered structured? |
||
/* @internal */ | ||
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral | ||
} | ||
|
@@ -1698,17 +1706,21 @@ namespace ts { | |
baseArrayType: TypeReference; // Array<T> where T is best common type of element types | ||
} | ||
|
||
export interface UnionType extends Type { | ||
export interface UnionOrIntersectionType extends Type { | ||
types: Type[]; // Constituent types | ||
/* @internal */ | ||
reducedType: Type; // Reduced union type (all subtypes removed) | ||
/* @internal */ | ||
resolvedProperties: SymbolTable; // Cache of resolved properties | ||
} | ||
|
||
export interface UnionType extends UnionOrIntersectionType { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add brands. |
||
|
||
export interface IntersectionType extends UnionOrIntersectionType { } | ||
|
||
/* @internal */ | ||
// Resolved object or union type | ||
export interface ResolvedType extends ObjectType, UnionType { | ||
// Resolved object, union, or intersection type | ||
export interface ResolvedType extends ObjectType, UnionOrIntersectionType { | ||
members: SymbolTable; // Properties by name | ||
properties: Symbol[]; // Properties | ||
callSignatures: Signature[]; // Call signatures of type | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice reuse!