-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Conditional types #21316
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
Conditional types #21316
Changes from 1 commit
57ca768
063eed1
ec2bdfd
43e195d
61225cc
9f74a7a
20434fa
ddc631c
000f121
27b945b
f59e2e6
14590f1
100e4f6
c5fd2f1
341c397
3f4911f
abc8110
bb23bb2
c10a552
53b1572
5094f76
925da86
e8d1740
15baf0e
9598acd
e96ec8c
d52fa71
4ec6fdd
fd0dd6e
c360c24
0e73240
5204fd5
eb314d0
cdd50d4
fc7d1c3
f19959a
b869290
4c7ec3c
b42c6b1
8e337b5
4f2b5f3
f990e4e
01516c8
d4dc67a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,6 +248,7 @@ namespace ts { | |
| TupleType, | ||
| UnionType, | ||
| IntersectionType, | ||
| ConditionalType, | ||
| ParenthesizedType, | ||
| ThisType, | ||
| TypeOperator, | ||
|
|
@@ -1065,6 +1066,14 @@ namespace ts { | |
| types: NodeArray<TypeNode>; | ||
| } | ||
|
|
||
| export interface ConditionalTypeNode extends TypeNode { | ||
| kind: SyntaxKind.ConditionalType; | ||
| checkType: TypeNode; | ||
|
Contributor
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. I'm still concerned that baking the
Member
Author
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. It's hard to speculate about what we might do here (i.e. nothing vs. additional conditions vs. discrete conditional operators), so I'm not keen on introducing more abstraction. |
||
| extendsType: TypeNode; | ||
| trueType: TypeNode; | ||
| falseType: TypeNode; | ||
| } | ||
|
|
||
| export interface ParenthesizedTypeNode extends TypeNode { | ||
| kind: SyntaxKind.ParenthesizedType; | ||
| type: TypeNode; | ||
|
|
@@ -3339,18 +3348,19 @@ namespace ts { | |
| Intersection = 1 << 18, // Intersection (T & U) | ||
| Index = 1 << 19, // keyof T | ||
| IndexedAccess = 1 << 20, // T[K] | ||
| Conditional = 1 << 21, // A extends B ? T : U | ||
| /* @internal */ | ||
| FreshLiteral = 1 << 21, // Fresh literal or unique type | ||
| FreshLiteral = 1 << 22, // Fresh literal or unique type | ||
| /* @internal */ | ||
| ContainsWideningType = 1 << 22, // Type is or contains undefined or null widening type | ||
| ContainsWideningType = 1 << 23, // Type is or contains undefined or null widening type | ||
| /* @internal */ | ||
| ContainsObjectLiteral = 1 << 23, // Type is or contains object literal type | ||
| ContainsObjectLiteral = 1 << 24, // Type is or contains object literal type | ||
| /* @internal */ | ||
| ContainsAnyFunctionType = 1 << 24, // Type is or contains the anyFunctionType | ||
| NonPrimitive = 1 << 25, // intrinsic object type | ||
| ContainsAnyFunctionType = 1 << 25, // Type is or contains the anyFunctionType | ||
| NonPrimitive = 1 << 26, // intrinsic object type | ||
| /* @internal */ | ||
| JsxAttributes = 1 << 26, // Jsx attributes type | ||
| MarkerType = 1 << 27, // Marker type used for variance probing | ||
| JsxAttributes = 1 << 27, // Jsx attributes type | ||
| MarkerType = 1 << 28, // Marker type used for variance probing | ||
|
|
||
| /* @internal */ | ||
| Nullable = Undefined | Null, | ||
|
|
@@ -3373,12 +3383,12 @@ namespace ts { | |
| ESSymbolLike = ESSymbol | UniqueESSymbol, | ||
| UnionOrIntersection = Union | Intersection, | ||
| StructuredType = Object | Union | Intersection, | ||
| StructuredOrTypeVariable = StructuredType | TypeParameter | Index | IndexedAccess, | ||
| TypeVariable = TypeParameter | IndexedAccess, | ||
| TypeVariable = TypeParameter | IndexedAccess | Conditional, | ||
| StructuredOrTypeVariable = StructuredType | TypeVariable | Index, | ||
|
|
||
| // 'Narrowable' types are types where narrowing actually narrows. | ||
| // This *should* be every type other than null, undefined, void, and never | ||
| Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive, | ||
| Narrowable = Any | StructuredOrTypeVariable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive, | ||
| NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive, | ||
| /* @internal */ | ||
| RequiresWidening = ContainsWideningType | ContainsObjectLiteral, | ||
|
|
@@ -3626,6 +3636,13 @@ namespace ts { | |
| type: TypeVariable | UnionOrIntersectionType; | ||
| } | ||
|
|
||
| export interface ConditionalType extends TypeVariable { | ||
| checkType: Type; | ||
| extendsType: Type; | ||
| trueType: Type; | ||
| falseType: Type; | ||
| } | ||
|
|
||
| export const enum SignatureKind { | ||
| Call, | ||
| Construct, | ||
|
|
||
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.
Spaces should be written using
writeSpace(), keywords usingwriteKeyword("extends"), and punctuation usingwritePunctuation("?")to support the symbol display builder integration with the emitter.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.
Everything else is written this way in emitter.ts. Are you saying it all needs to change?
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.
Nevermind, I was looking at the old declaration emitter. I will fix this.