diff --git a/packages/typescript/src/api/async/api.ts b/packages/typescript/src/api/async/api.ts index ef6d7fb7ef10b..de9bf82fe65d3 100644 --- a/packages/typescript/src/api/async/api.ts +++ b/packages/typescript/src/api/async/api.ts @@ -125,6 +125,7 @@ import type { TemplateLiteralType, ThisTypePredicate, TupleType, + TupleTypeReference, Type, TypeParameter, TypePredicate, @@ -187,6 +188,7 @@ export type { TimingAccumulators, TimingInfo, TupleType, + TupleTypeReference, Type, TypeAcquisition, TypeParameter, diff --git a/packages/typescript/src/api/async/types.ts b/packages/typescript/src/api/async/types.ts index 79c392aed6b63..37d1e10f4463e 100644 --- a/packages/typescript/src/api/async/types.ts +++ b/packages/typescript/src/api/async/types.ts @@ -177,6 +177,12 @@ export interface TypeReference extends ObjectType { getTarget(): Promise; } +/** References to tuple types */ +export interface TupleTypeReference extends TypeReference { + /** Get the tuple type that describes this reference's shape */ + getTarget(): Promise; +} + /** Interface types — classes and interfaces (ObjectFlags.ClassOrInterface) */ export interface InterfaceType extends TypeReference { /** Get all type parameters (outer + local, excluding thisType) */ diff --git a/packages/typescript/src/api/sync/api.ts b/packages/typescript/src/api/sync/api.ts index b92a3fa26fb72..fc439a4424b61 100644 --- a/packages/typescript/src/api/sync/api.ts +++ b/packages/typescript/src/api/sync/api.ts @@ -142,6 +142,7 @@ import type { TemplateLiteralType, ThisTypePredicate, TupleType, + TupleTypeReference, Type, TypeParameter, TypePredicate, @@ -204,6 +205,7 @@ export type { TimingAccumulators, TimingInfo, TupleType, + TupleTypeReference, Type, TypeAcquisition, TypeParameter, diff --git a/packages/typescript/src/api/sync/types.ts b/packages/typescript/src/api/sync/types.ts index 43a650ef67621..bdb25aeb59b66 100644 --- a/packages/typescript/src/api/sync/types.ts +++ b/packages/typescript/src/api/sync/types.ts @@ -244,6 +244,15 @@ export interface TypeReference extends ObjectType { }; } +/** References to tuple types */ +export interface TupleTypeReference extends TypeReference { + /** Get the tuple type that describes this reference's shape */ + getTarget: { + (): TupleType; + gen(): Generator; + }; +} + /** Interface types — classes and interfaces (ObjectFlags.ClassOrInterface) */ export interface InterfaceType extends TypeReference { /** Get all type parameters (outer + local, excluding thisType) */ diff --git a/packages/typescript/test/async/api.test.ts b/packages/typescript/test/async/api.test.ts index b40091c90d6c9..1622f40a694b0 100644 --- a/packages/typescript/test/async/api.test.ts +++ b/packages/typescript/test/async/api.test.ts @@ -70,6 +70,7 @@ import { SymbolFlags, type TemplateLiteralType, type TextEdit, + type TupleTypeReference, TypeFlags, TypeFormatFlags, type TypeParameter, @@ -2730,11 +2731,13 @@ export const tuple: readonly [number, string?, ...boolean[]] = [1]; const { type, api } = await getTypeAtName(spawnAPI(typeFiles), "tuple:"); try { assert.ok(type.flags & TypeFlags.Object); - const ref = type as TypeReference; + const ref = type as TupleTypeReference; assert.ok(ref.objectFlags & ObjectFlags.Reference); const target = await ref.getTarget(); assert.ok(target); assert.ok(target.flags & TypeFlags.Object); + assert.deepStrictEqual(target.elementFlags, [1, 2, 4]); + assert.equal(target.readonly, true); } finally { await api.close(); diff --git a/packages/typescript/test/sync/api.test.ts b/packages/typescript/test/sync/api.test.ts index d534bc20a6e4e..7007626925b27 100644 --- a/packages/typescript/test/sync/api.test.ts +++ b/packages/typescript/test/sync/api.test.ts @@ -80,6 +80,7 @@ import { SymbolFlags, type TemplateLiteralType, type TextEdit, + type TupleTypeReference, TypeFlags, TypeFormatFlags, type TypeParameter, @@ -2646,11 +2647,13 @@ export const tuple: readonly [number, string?, ...boolean[]] = [1]; const { type, api } = getTypeAtName(spawnAPI(typeFiles), "tuple:"); try { assert.ok(type.flags & TypeFlags.Object); - const ref = type as TypeReference; + const ref = type as TupleTypeReference; assert.ok(ref.objectFlags & ObjectFlags.Reference); const target = ref.getTarget(); assert.ok(target); assert.ok(target.flags & TypeFlags.Object); + assert.deepStrictEqual(target.elementFlags, [1, 2, 4]); + assert.equal(target.readonly, true); } finally { api.close();