-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make isTypeAssignableTo public on TypeChecker #56448
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a doc; please leave suggestions! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking on what I'd want as a user, it's mostly just knowing what kind of caching I'd have to worry about (since that was brought up by TS folks previously) and examples of what direction the assignability runs in. Vaguely: /**
* Performs an assignability check, including using persistent caches.
* @returns Whether `source` is assignable to `type`.
* @example
* ```ts
* declare const literal: ts.Type; // Type of "abc"
* declare const primitive: ts.Type; // Type of string
* isTypeAssignableTo(literal, literal); // true
* isTypeAssignableTo(literal, primitive); // true
* isTypeAssignableTo(primitive, literal); // false
* isTypeAssignableTo(primitive, primitive); // true
* ```
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added something similar to the above. |
||
/** @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[]): Type; | ||
/** @internal */ createSignature( | ||
declaration: SignatureDeclaration | undefined, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.