Typescript - Tuples can include rest elements (#8805)
This commit is contained in:
@@ -511,7 +511,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
|
||||
tsParseTupleElementType(): N.TsType {
|
||||
// parses `...TsType[]`
|
||||
if (this.match(tt.ellipsis)) {
|
||||
const restNode: N.TsRestType = this.startNode();
|
||||
this.next(); // skips ellipsis
|
||||
restNode.typeAnnotation = this.tsParseType();
|
||||
return this.finishNode(restNode, "TSRestType");
|
||||
}
|
||||
|
||||
const type = this.tsParseType();
|
||||
// parses `TsType?`
|
||||
if (this.eat(tt.question)) {
|
||||
const optionalTypeNode: N.TsOptionalType = this.startNodeAtNode(type);
|
||||
optionalTypeNode.typeAnnotation = type;
|
||||
|
||||
@@ -1105,6 +1105,7 @@ export type TsType =
|
||||
| TsArrayType
|
||||
| TsTupleType
|
||||
| TsOptionalType
|
||||
| TsRestType
|
||||
| TsUnionOrIntersectionType
|
||||
| TsConditionalType
|
||||
| TsInferType
|
||||
@@ -1190,6 +1191,11 @@ export type TsOptionalType = TsTypeBase & {
|
||||
typeAnnotation: TsType,
|
||||
};
|
||||
|
||||
export type TsRestType = TsTypeBase & {
|
||||
type: "TSRestType",
|
||||
typeAnnotation: TsType,
|
||||
};
|
||||
|
||||
export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType;
|
||||
|
||||
export type TsUnionOrIntersectionTypeBase = TsTypeBase & {
|
||||
|
||||
Reference in New Issue
Block a user