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
127 changes: 127 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,20 @@ export class Checker {
return type.getNonNullableType();
}

/**
* Add `undefined` and/or `null` to a type, as indicated by `flags` (a combination of
* {@link TypeFlags.Undefined} and {@link TypeFlags.Null}). Always returns a type.
*/
async getNullableType(type: Type, flags: TypeFlags): Promise<Type> {
const data = await this.client.apiRequest("getNullableType", {
snapshot: this.snapshotId,
project: this.project.handle,
type: type.id,
flags,
});
return this.objectRegistry.getOrCreateType(data);
}

/**
* Get the type for a type node. Always returns a type; for type nodes whose
* type cannot be determined the checker yields the error type (use
Expand Down Expand Up @@ -2746,6 +2760,84 @@ export class Checker {
async getNonPrimitiveType(): Promise<Type> {
return this.getIntrinsicType("getNonPrimitiveType");
}
async getFalseType(): Promise<Type> {
return this.getIntrinsicType("getFalseType");
}
async getTrueType(): Promise<Type> {
return this.getIntrinsicType("getTrueType");
}

/** Get (or create) the singleton type for a string literal value. Always returns a type. */
async getStringLiteralType(value: string): Promise<Type> {
const data = await this.client.apiRequest("getStringLiteralType", {
snapshot: this.snapshotId,
project: this.project.handle,
value,
});
return this.objectRegistry.getOrCreateType(data);
}

/** Get (or create) the singleton type for a numeric literal value. Always returns a type. */
async getNumberLiteralType(value: number): Promise<Type> {
const data = await this.client.apiRequest("getNumberLiteralType", {
snapshot: this.snapshotId,
project: this.project.handle,
value,
});
return this.objectRegistry.getOrCreateType(data);
}

/** Get (or create) the singleton type for a bigint literal value. Always returns a type. */
async getBigIntLiteralType(value: bigint): Promise<Type> {
const negative = value < 0n;
const absValue = negative ? -value : value;
const base10Value = absValue === 0n ? "" : absValue.toString();
const data = await this.client.apiRequest("getBigIntLiteralType", {
snapshot: this.snapshotId,
project: this.project.handle,
negative,
base10Value,
});
return this.objectRegistry.getOrCreateType(data);
}

/**
* Get the augmented properties of a type: its properties, plus (when the type has call or
* construct signatures) the properties of the global `CallableFunction`/`NewableFunction`
* interfaces not already present.
*/
async getAugmentedPropertiesOfType(type: Type): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest("getAugmentedPropertiesOfType", {
snapshot: this.snapshotId,
project: this.project.handle,
objectId: type.id,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

async getJsxIntrinsicTagNamesAt(location: Node): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest("getJsxIntrinsicTagNamesAt", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(location),
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

/**
* Look up a private identifier (e.g. `"#foo"`, including the leading `#`) lexically in scope
* at `location`, and if found, return the corresponding property of `type`.
*/
async getPrivateIdentifierPropertyOfType(type: Type, name: string, location: Node): Promise<Symbol | undefined> {
const data = await this.client.apiRequest("getPrivateIdentifierPropertyOfType", {
snapshot: this.snapshotId,
project: this.project.handle,
type: type.id,
name,
location: getNodeRequestHandle(location),
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

async typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: number): Promise<TypeNode | undefined> {
const binaryData = await this.client.apiRequestBinary("typeToTypeNode", {
Expand Down Expand Up @@ -2825,6 +2917,41 @@ export class Checker {
});
}

/**
* Returns `true` if the function-like declaration is the implementation
* signature of a set of overloads (i.e. it has a body and is not a
* get/set accessor).
*/
async isImplementationOfOverload(node: Node): Promise<boolean> {
return this.client.apiRequest("isImplementationOfOverload", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(node),
});
}

/**
* Get the property symbol corresponding to an identifier in a destructuring
* assignment or `for..of` statement, e.g. `a` in `({ property1: a } = obj)`.
*/
async getPropertySymbolOfDestructuringAssignment(location: Identifier): Promise<Symbol | undefined> {
const data = await this.client.apiRequest("getPropertySymbolOfDestructuringAssignment", {
snapshot: this.snapshotId,
project: this.project.handle,
location: getNodeRequestHandle(location),
});
return data ? this.objectRegistry.getOrCreateSymbol(data) : undefined;
}

/** Get all ambient modules declared in the program (e.g. `declare module "foo" { ... }`). */
async getAmbientModules(): Promise<readonly Symbol[]> {
const data = await this.client.apiRequest("getAmbientModules", {
snapshot: this.snapshotId,
project: this.project.handle,
});
return data ? data.map(d => this.objectRegistry.getOrCreateSymbol(d)) : [];
}

/** Get the return type of a signature. Always returns a type. */
async getReturnTypeOfSignature(signature: Signature): Promise<Type> {
return signature.getReturnType();
Expand Down
Loading
Loading