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
2 changes: 2 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import type {
TemplateLiteralType,
ThisTypePredicate,
TupleType,
TupleTypeReference,
Type,
TypeParameter,
TypePredicate,
Expand Down Expand Up @@ -187,6 +188,7 @@ export type {
TimingAccumulators,
TimingInfo,
TupleType,
TupleTypeReference,
Type,
TypeAcquisition,
TypeParameter,
Expand Down
6 changes: 6 additions & 0 deletions packages/typescript/src/api/async/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ export interface TypeReference extends ObjectType {
getTarget(): Promise<Type>;
}

/** References to tuple types */
export interface TupleTypeReference extends TypeReference {
/** Get the tuple type that describes this reference's shape */
getTarget(): Promise<TupleType>;
Comment thread
mrazauskas marked this conversation as resolved.
}

/** Interface types — classes and interfaces (ObjectFlags.ClassOrInterface) */
export interface InterfaceType extends TypeReference {
/** Get all type parameters (outer + local, excluding thisType) */
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import type {
TemplateLiteralType,
ThisTypePredicate,
TupleType,
TupleTypeReference,
Type,
TypeParameter,
TypePredicate,
Expand Down Expand Up @@ -204,6 +205,7 @@ export type {
TimingAccumulators,
TimingInfo,
TupleType,
TupleTypeReference,
Type,
TypeAcquisition,
TypeParameter,
Expand Down
9 changes: 9 additions & 0 deletions packages/typescript/src/api/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtocolRequest, TupleType, ProtocolResponse["result"]>;
Comment thread
mrazauskas marked this conversation as resolved.
};
}

/** Interface types — classes and interfaces (ObjectFlags.ClassOrInterface) */
export interface InterfaceType extends TypeReference {
/** Get all type parameters (outer + local, excluding thisType) */
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript/test/async/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
SymbolFlags,
type TemplateLiteralType,
type TextEdit,
type TupleTypeReference,
TypeFlags,
TypeFormatFlags,
type TypeParameter,
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript/test/sync/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
SymbolFlags,
type TemplateLiteralType,
type TextEdit,
type TupleTypeReference,
TypeFlags,
TypeFormatFlags,
type TypeParameter,
Expand Down Expand Up @@ -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();
Expand Down