diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b55a308e91f65..bc833556d8062 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5158,7 +5158,20 @@ export interface TypeChecker { /** @internal */ getPromiseLikeType(): Type; /** @internal */ getAsyncIterableType(): Type | undefined; - /** @internal */ isTypeAssignableTo(source: Type, target: Type): boolean; + /** + * 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( declaration: SignatureDeclaration | undefined, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1ed2cd96de1e3..235f8aeed7c3b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6832,6 +6832,20 @@ 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. * This function will _not_ return true if passed a type which