Make isTypeAssignableTo public on TypeChecker (#56448)

This commit is contained in:
Jake Bailey
2023-12-08 13:16:52 -08:00
committed by GitHub
parent 41ec497211
commit 14da488969
2 changed files with 28 additions and 1 deletions
+14 -1
View File
@@ -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,
+14
View File
@@ -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