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 @@ -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
5 changes: 4 additions & 1 deletion 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,6 +199,9 @@ export interface InterfaceType extends TypeReference {
getLocalTypeParameters(): Promise<readonly TypeParameter[]>;
}

/** Generic types */
export type GenericType = InterfaceType & TypeReference;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact type definition in Strada is:

interface GenericType extends InterfaceType, TypeReference {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to an intersection?


/** Tuple type targets (ObjectFlags.Tuple) */
export interface TupleType extends InterfaceType {
/** Get this tuple target */
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
7 changes: 5 additions & 2 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,6 +278,9 @@ export interface InterfaceType extends TypeReference {
};
}

/** Generic types */
export type GenericType = InterfaceType & TypeReference;

/** Tuple type targets (ObjectFlags.Tuple) */
export interface TupleType extends InterfaceType {
/** Get this tuple target */
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