Skip to content
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

Expose getStringLiteralType and getNumberLiteralType on the TypeChecker, plus remove /** @internal */ from several useful methods. #52473

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
createIndexInfo,
getAnyType: () => anyType,
getStringType: () => stringType,
getStringLiteralType,
getNumberType: () => numberType,
getNumberLiteralType,
getBigIntType: () => bigintType,
createPromiseType,
createArrayType,
getElementTypeOfArrayType,
Expand Down
51 changes: 40 additions & 11 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5099,17 +5099,46 @@ export interface TypeChecker {
getBaseConstraintOfType(type: Type): Type | undefined;
getDefaultFromTypeParameter(type: Type): Type | undefined;

/** @internal */ getAnyType(): Type;
/** @internal */ getStringType(): Type;
/** @internal */ getNumberType(): Type;
/** @internal */ getBooleanType(): Type;
/** @internal */ getFalseType(fresh?: boolean): Type;
/** @internal */ getTrueType(fresh?: boolean): Type;
/** @internal */ getVoidType(): Type;
/** @internal */ getUndefinedType(): Type;
/** @internal */ getNullType(): Type;
/** @internal */ getESSymbolType(): Type;
/** @internal */ getNeverType(): Type;
/**
* Gets the intrinsic `any` type. There are multiple types that act as `any` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `any`. Instead, use `type.flags & TypeFlags.Any`.
*/
getAnyType(): Type;
getStringType(): Type;
getStringLiteralType(value: string): StringLiteralType;
getNumberType(): Type;
getNumberLiteralType(value: number): NumberLiteralType;
getBigIntType(): Type;
getBooleanType(): Type;
/* eslint-disable @typescript-eslint/unified-signatures */
/** @internal */
getFalseType(fresh?: boolean): Type;
getFalseType(): Type;
/** @internal */
getTrueType(fresh?: boolean): Type;
getTrueType(): Type;
/* eslint-enable @typescript-eslint/unified-signatures */
getVoidType(): Type;
/**
* Gets the intrinsic `undefined` type. There are multiple types that act as `undefined` used internally in the compiler
* depending on compiler options, so the type returned by this function should not be used in equality checks to determine
* if another type is `undefined`. Instead, use `type.flags & TypeFlags.Undefined`.
*/
getUndefinedType(): Type;
/**
* Gets the intrinsic `null` type. There are multiple types that act as `null` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `null`. Instead, use `type.flags & TypeFlags.Null`.
*/
getNullType(): Type;
getESSymbolType(): Type;
/**
* Gets the intrinsic `never` type. There are multiple types that act as `never` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `never`. Instead, use `type.flags & TypeFlags.Never`.
*/
getNeverType(): Type;
/** @internal */ getOptionalType(): Type;
/** @internal */ getUnionType(types: Type[], subtypeReduction?: UnionReduction): Type;
/** @internal */ createArrayType(elementType: Type): Type;
Expand Down
34 changes: 34 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6401,6 +6401,40 @@ declare namespace ts {
getApparentType(type: Type): Type;
getBaseConstraintOfType(type: Type): Type | undefined;
getDefaultFromTypeParameter(type: Type): Type | undefined;
/**
* Gets the intrinsic `any` type. There are multiple types that act as `any` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `any`. Instead, use `type.flags & TypeFlags.Any`.
*/
getAnyType(): Type;
getStringType(): Type;
getStringLiteralType(value: string): StringLiteralType;
getNumberType(): Type;
getNumberLiteralType(value: number): NumberLiteralType;
getBigIntType(): Type;
getBooleanType(): Type;
getFalseType(): Type;
getTrueType(): Type;
getVoidType(): Type;
/**
* Gets the intrinsic `undefined` type. There are multiple types that act as `undefined` used internally in the compiler
* depending on compiler options, so the type returned by this function should not be used in equality checks to determine
* if another type is `undefined`. Instead, use `type.flags & TypeFlags.Undefined`.
*/
getUndefinedType(): Type;
/**
* Gets the intrinsic `null` type. There are multiple types that act as `null` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `null`. Instead, use `type.flags & TypeFlags.Null`.
*/
getNullType(): Type;
getESSymbolType(): Type;
/**
* Gets the intrinsic `never` type. There are multiple types that act as `never` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `never`. Instead, use `type.flags & TypeFlags.Never`.
*/
getNeverType(): Type;
/**
* 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
34 changes: 34 additions & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,40 @@ declare namespace ts {
getApparentType(type: Type): Type;
getBaseConstraintOfType(type: Type): Type | undefined;
getDefaultFromTypeParameter(type: Type): Type | undefined;
/**
* Gets the intrinsic `any` type. There are multiple types that act as `any` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `any`. Instead, use `type.flags & TypeFlags.Any`.
*/
getAnyType(): Type;
getStringType(): Type;
getStringLiteralType(value: string): StringLiteralType;
getNumberType(): Type;
getNumberLiteralType(value: number): NumberLiteralType;
getBigIntType(): Type;
getBooleanType(): Type;
getFalseType(): Type;
getTrueType(): Type;
getVoidType(): Type;
/**
* Gets the intrinsic `undefined` type. There are multiple types that act as `undefined` used internally in the compiler
* depending on compiler options, so the type returned by this function should not be used in equality checks to determine
* if another type is `undefined`. Instead, use `type.flags & TypeFlags.Undefined`.
*/
getUndefinedType(): Type;
/**
* Gets the intrinsic `null` type. There are multiple types that act as `null` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `null`. Instead, use `type.flags & TypeFlags.Null`.
*/
getNullType(): Type;
getESSymbolType(): Type;
/**
* Gets the intrinsic `never` type. There are multiple types that act as `never` used internally in the compiler,
* so the type returned by this function should not be used in equality checks to determine if another type
* is `never`. Instead, use `type.flags & TypeFlags.Never`.
*/
getNeverType(): Type;
/**
* 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