From 335cea47f44739f18198b78a2726f9cf4df2c753 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:39:52 -0800 Subject: [PATCH 1/2] Export isTypeAssignableTo on TypeChecker --- src/compiler/types.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 34a2835822302..eed89d2326d3e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5158,7 +5158,7 @@ export interface TypeChecker { /** @internal */ getPromiseLikeType(): Type; /** @internal */ getAsyncIterableType(): Type | undefined; - /** @internal */ isTypeAssignableTo(source: Type, target: Type): boolean; + isTypeAssignableTo(source: Type, target: Type): boolean; /** @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): Type; /** @internal */ createSignature( declaration: SignatureDeclaration | undefined, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7135bb7863324..1e21d2b07f651 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6829,6 +6829,7 @@ declare namespace ts { * is `never`. Instead, use `type.flags & TypeFlags.Never`. */ getNeverType(): Type; + isTypeAssignableTo(source: Type, target: Type): boolean; /** * True if this type is the `Array` or `ReadonlyArray` type from lib.d.ts. * This function will _not_ return true if passed a type which From 1ef7d153a02477da9146fd9ce85e51d8e5907e3b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:51:11 -0800 Subject: [PATCH 2/2] Add some sort of docstring --- src/compiler/types.ts | 13 +++++++++++++ tests/baselines/reference/api/typescript.d.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eed89d2326d3e..01084e4ed6e53 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5158,6 +5158,19 @@ export interface TypeChecker { /** @internal */ getPromiseLikeType(): Type; /** @internal */ getAsyncIterableType(): Type | undefined; + /** + * Returns true if the "source" type is assignable to the "target" type. + * + * ```ts + * declare const abcLiteral: ts.Type; // Type of "abc" + * declare const stringType: ts.Type; // Type of string + * + * isTypeAssignableTo(abcLiteral, abcLiteral); // true; "abc" is assignable to "abc" + * isTypeAssignableTo(abcLiteral, stringType); // true; "abc" is assignable to string + * isTypeAssignableTo(stringType, abcLiteral); // false; string is not assignable to "abc" + * isTypeAssignableTo(stringType, stringType); // true; string is assignable to string + * ``` + */ isTypeAssignableTo(source: Type, target: Type): boolean; /** @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): Type; /** @internal */ createSignature( diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1e21d2b07f651..dc285d91c2eaf 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6829,6 +6829,19 @@ declare namespace ts { * is `never`. Instead, use `type.flags & TypeFlags.Never`. */ getNeverType(): Type; + /** + * Returns true if the "source" type is assignable to the "target" type. + * + * ```ts + * declare const abcLiteral: ts.Type; // Type of "abc" + * declare const stringType: ts.Type; // Type of string + * + * isTypeAssignableTo(abcLiteral, abcLiteral); // true; "abc" is assignable to "abc" + * isTypeAssignableTo(abcLiteral, stringType); // true; "abc" is assignable to string + * isTypeAssignableTo(stringType, abcLiteral); // false; string is not assignable to "abc" + * isTypeAssignableTo(stringType, stringType); // true; string is assignable to string + * ``` + */ isTypeAssignableTo(source: Type, target: Type): boolean; /** * True if this type is the `Array` or `ReadonlyArray` type from lib.d.ts.