Skip to content
Merged
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 @@ -112,6 +112,7 @@ import type {
EmitResult,
FormatDiagnosticsHost,
FreshableType,
GenericType,
GetImportEditsForSymbolsOptions,
IdentifierTypePredicate,
ImportAdderAction as APIImportAdderAction,
Expand Down Expand Up @@ -169,6 +170,7 @@ export type {
EmitResult,
FormatDiagnosticsHost,
FreshableType,
GenericType,
GetImportEditsForSymbolsOptions,
IdentifierTypePredicate,
IndexedAccessType,
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript/src/api/async/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export interface ObjectType extends Type {
/** Type references (ObjectFlags.Reference) — e.g. Array<string>, Map<K, V> */
export interface TypeReference extends ObjectType {
/** Get the generic target type (e.g. Array for Array<string>) */
getTarget(): Promise<Type>;
getTarget(): Promise<GenericType>;
}

/** References to tuple types */
Expand All @@ -199,8 +199,12 @@ export interface InterfaceType extends TypeReference {
getLocalTypeParameters(): Promise<readonly TypeParameter[]>;
}

/** Generic types */
export interface GenericType extends InterfaceType, TypeReference {
}

/** Tuple type targets (ObjectFlags.Tuple) */
export interface TupleType extends InterfaceType {
export interface TupleType extends GenericType {
/** Get this tuple target */
getTarget(): Promise<TupleType>;
/** Per-element flags (Required, Optional, Rest, Variadic) */
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 @@ -129,6 +129,7 @@ import type {
EmitResult,
FormatDiagnosticsHost,
FreshableType,
GenericType,
GetImportEditsForSymbolsOptions,
IdentifierTypePredicate,
ImportAdderAction as APIImportAdderAction,
Expand Down Expand Up @@ -186,6 +187,7 @@ export type {
EmitResult,
FormatDiagnosticsHost,
FreshableType,
GenericType,
GetImportEditsForSymbolsOptions,
IdentifierTypePredicate,
IndexedAccessType,
Expand Down
10 changes: 7 additions & 3 deletions packages/typescript/src/api/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export interface ObjectType extends Type {
export interface TypeReference extends ObjectType {
/** Get the generic target type (e.g. Array for Array<string>) */
getTarget: {
(): Type;
gen(): Generator<ProtocolRequest, Type, ProtocolResponse["result"]>;
(): GenericType;
gen(): Generator<ProtocolRequest, GenericType, ProtocolResponse["result"]>;
};
}

Expand Down Expand Up @@ -278,8 +278,12 @@ export interface InterfaceType extends TypeReference {
};
}

/** Generic types */
export interface GenericType extends InterfaceType, TypeReference {
}

/** Tuple type targets (ObjectFlags.Tuple) */
export interface TupleType extends InterfaceType {
export interface TupleType extends GenericType {
/** Get this tuple target */
getTarget: {
(): TupleType;
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/test/async/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,9 @@ export const tuple: readonly [number, string?, ...boolean[]] = [1];
const target = await ref.getTarget();
assert.ok(target);
assert.ok(target.flags & TypeFlags.Object);
const typeParameters = await target.getTypeParameters();
assert.ok(typeParameters);
assert.equal(typeParameters.length, 1);
const properties = await type.getProperties();
assert.ok(properties.some(property => property.name === "length"));
assert.equal((await type.getProperty("length"))?.name, "length");
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/test/sync/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,9 @@ export const tuple: readonly [number, string?, ...boolean[]] = [1];
const target = ref.getTarget();
assert.ok(target);
assert.ok(target.flags & TypeFlags.Object);
const typeParameters = target.getTypeParameters();
assert.ok(typeParameters);
assert.equal(typeParameters.length, 1);
const properties = type.getProperties();
assert.ok(properties.some(property => property.name === "length"));
assert.equal((type.getProperty("length"))?.name, "length");
Expand Down