Skip to content

Commit

Permalink
Make isTypeAssignableTo public on TypeChecker (#56448)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Dec 8, 2023
1 parent 41ec497 commit 14da488
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14da488

Please sign in to comment.