Skip to content

Commit 42af237

Browse files
committed
Handle @inline on tuple types
Resolves #2932
1 parent 4bf00b5 commit 42af237

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Changelog
44

55
## Unreleased
66

7+
### Bug Fixes
8+
9+
- `@inline` now functions when referencing tuple types, #2932.
10+
711
## v0.28.2 (2025-04-07)
812

913
### Features

src/lib/converter/types.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ const thisConverter: TypeConverter<ts.ThisTypeNode> = {
10091009
},
10101010
};
10111011

1012-
const tupleConverter: TypeConverter<ts.TupleTypeNode, ts.TupleTypeReference> = {
1012+
const tupleConverter = {
10131013
kind: [ts.SyntaxKind.TupleType],
10141014
convert(context, node) {
10151015
const elements = node.elements.map((node) => convertType(context, node));
@@ -1061,7 +1061,7 @@ const tupleConverter: TypeConverter<ts.TupleTypeNode, ts.TupleTypeReference> = {
10611061

10621062
return new TupleType(elements ?? []);
10631063
},
1064-
};
1064+
} satisfies TypeConverter<ts.TupleTypeNode, ts.TupleTypeReference>;
10651065

10661066
const supportedOperatorNames = {
10671067
[ts.SyntaxKind.KeyOfKeyword]: "keyof",
@@ -1265,6 +1265,12 @@ function convertTypeInlined(context: Context, type: ts.Type): SomeType {
12651265
const elementType = convertType(context, context.checker.getTypeArguments(type as ts.TypeReference)[0]);
12661266
return new ArrayType(elementType);
12671267
}
1268+
if (isTypeReference(type) && context.checker.isTupleType(type)) {
1269+
const tupleNode = context.checker.typeToTypeNode(type.target, void 0, ts.NodeBuilderFlags.IgnoreErrors)!;
1270+
if (ts.isTupleTypeNode(tupleNode)) {
1271+
return tupleConverter.convertType(context, type as ts.TupleTypeReference, tupleNode);
1272+
}
1273+
}
12681274

12691275
return typeLiteralConverter.convertType(
12701276
context,

src/lib/utils-common/array.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const emptyArray: readonly [] = [];
33
/**
44
* Inserts an item into an array sorted by priority. If two items have the same priority,
55
* the item will be inserted later will be placed later in the array.
6+
* Higher priority is placed earlier in the array.
67
* @param arr modified by inserting item.
78
* @param item
89
*/

src/lib/utils-common/events.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class EventDispatcher<T extends Record<keyof T, unknown[]>> {
2222
* @param event the event to listen to.
2323
* @param listener function to be called when an this event is emitted.
2424
* @param priority optional priority to insert this hook with.
25+
* Higher priority is placed earlier in the listener array.
2526
*/
2627
on<K extends keyof T>(
2728
event: K,

src/test/converter2/issues/gh2932.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @inline
3+
*/
4+
type Vector2D = [start: number, end: number];
5+
6+
export function doStuff([start, end]: Vector2D) {}

src/test/issues.c2.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2115,4 +2115,10 @@ describe("Issue Tests", () => {
21152115
const EdgeCases = query(project, "EdgeCases");
21162116
equal(EdgeCases.typeParameters?.map(t => t.type?.toString()), ["number", undefined]);
21172117
});
2118+
2119+
it("#2932 handles @inline on tuple types", () => {
2120+
const project = convert();
2121+
const sig = querySig(project, "doStuff");
2122+
equal(sig.parameters?.[0].type?.toString(), "[start: number, end: number]");
2123+
});
21182124
});

0 commit comments

Comments
 (0)