Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const TypeScriptError = {
'You can either wrap the instantiation expression in parentheses, or delete the type arguments.',
InvalidTupleMemberLabel: 'Tuple members must be labeled with a simple identifier.',
MissingInterfaceName: "'interface' declarations must be followed by an identifier.",
MixedLabeledAndUnlabeledElements: 'Tuple members must all have names or all not have names.',
NonAbstractClassHasAbstractMethod: 'Abstract methods can only appear within an abstract class.',
NonClassMethodPropertyHasAbstractModifer:
"'abstract' modifier can only appear on a class, method, or property declaration.",
Expand Down
7 changes: 0 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,6 @@ export function tsPlugin(options?: {
// Validate the elementTypes to ensure that no mandatory elements
// follow optional elements
let seenOptionalElement = false;
let labeledElements: boolean | null = null;
node.elementTypes.forEach((elementNode) => {
const { type } = elementNode;

Expand All @@ -1714,12 +1713,6 @@ export function tsPlugin(options?: {
elementNode = elementNode.typeAnnotation;
checkType = elementNode.type;
}

const isLabeled = checkType === 'TSNamedTupleMember';
labeledElements ??= isLabeled;
if (labeledElements !== isLabeled) {
this.raise(elementNode.start, TypeScriptError.MixedLabeledAndUnlabeledElements);
}
});

return this.finishNode(node, 'TSTupleType');
Expand Down
158 changes: 158 additions & 0 deletions test/tuple_named_and_anonymous_mixed/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"type": "Program",
"start": 0,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"body": [
{
"type": "TSTypeAliasDeclaration",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 36
}
},
"id": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"name": "A"
},
"typeAnnotation": {
"type": "TSTupleType",
"start": 9,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 35
}
},
"elementTypes": [
{
"type": "TSNamedTupleMember",
"start": 10,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 21
}
},
"optional": false,
"label": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
}
},
"name": "foo"
},
"elementType": {
"type": "TSStringKeyword",
"start": 15,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 21
}
}
}
},
{
"type": "TSRestType",
"start": 23,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 34
}
},
"typeAnnotation": {
"type": "TSArrayType",
"start": 26,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 34
}
},
"elementType": {
"type": "TSNumberKeyword",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 32
}
}
}
}
}
]
}
}
],
"sourceType": "module"
}
1 change: 1 addition & 0 deletions test/tuple_named_and_anonymous_mixed/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type A = [foo: string, ...number[]];