Skip to content

Commit

Permalink
Expose getStringLiteralType and getNumberLiteralType on the TypeCheck…
Browse files Browse the repository at this point in the history
…er, plus remove /** @internal */ from several useful methods. (#52473)

Co-authored-by: Stephen Stchur <[email protected]>
Co-authored-by: Andrew Branch <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2023
1 parent 9f8a160 commit 5e898eb
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,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 @@ -6369,6 +6369,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

0 comments on commit 5e898eb

Please sign in to comment.