Skip to content

Commit 9ee3315

Browse files
authored
Make getTypeOfSymbol, isArrayType, isTupleType public on TypeChecker (#52467)
1 parent 8fd1308 commit 9ee3315

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/compiler/types.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4927,7 +4927,7 @@ export interface TypeCheckerHost extends ModuleSpecifierResolutionHost {
49274927

49284928
export interface TypeChecker {
49294929
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
4930-
/** @internal */ getTypeOfSymbol(symbol: Symbol): Type;
4930+
getTypeOfSymbol(symbol: Symbol): Type;
49314931
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
49324932
getPropertiesOfType(type: Type): Symbol[];
49334933
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
@@ -5153,9 +5153,21 @@ export interface TypeChecker {
51535153
/** @internal */ getRecursionIdentity(type: Type): object | undefined;
51545154
/** @internal */ getUnmatchedProperties(source: Type, target: Type, requireOptionalProperties: boolean, matchDiscriminantProperties: boolean): IterableIterator<Symbol>;
51555155

5156-
/** @internal */ isArrayType(type: Type): boolean;
5157-
/** @internal */ isTupleType(type: Type): boolean;
5158-
/** @internal */ isArrayLikeType(type: Type): boolean;
5156+
/**
5157+
* True if this type is the `Array` or `ReadonlyArray` type from lib.d.ts.
5158+
* This function will _not_ return true if passed a type which
5159+
* extends `Array` (for example, the TypeScript AST's `NodeArray` type).
5160+
*/
5161+
isArrayType(type: Type): boolean;
5162+
/**
5163+
* True if this type is a tuple type. This function will _not_ return true if
5164+
* passed a type which extends from a tuple.
5165+
*/
5166+
isTupleType(type: Type): boolean;
5167+
/**
5168+
* True if this type is assignable to `ReadonlyArray<any>`.
5169+
*/
5170+
isArrayLikeType(type: Type): boolean;
51595171

51605172
/**
51615173
* True if `contextualType` should not be considered for completions because

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,6 +6310,7 @@ declare namespace ts {
63106310
}
63116311
interface TypeChecker {
63126312
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
6313+
getTypeOfSymbol(symbol: Symbol): Type;
63136314
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
63146315
getPropertiesOfType(type: Type): Symbol[];
63156316
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
@@ -6400,6 +6401,21 @@ declare namespace ts {
64006401
getApparentType(type: Type): Type;
64016402
getBaseConstraintOfType(type: Type): Type | undefined;
64026403
getDefaultFromTypeParameter(type: Type): Type | undefined;
6404+
/**
6405+
* True if this type is the `Array` or `ReadonlyArray` type from lib.d.ts.
6406+
* This function will _not_ return true if passed a type which
6407+
* extends `Array` (for example, the TypeScript AST's `NodeArray` type).
6408+
*/
6409+
isArrayType(type: Type): boolean;
6410+
/**
6411+
* True if this type is a tuple type. This function will _not_ return true if
6412+
* passed a type which extends from a tuple.
6413+
*/
6414+
isTupleType(type: Type): boolean;
6415+
/**
6416+
* True if this type is assignable to `ReadonlyArray<any>`.
6417+
*/
6418+
isArrayLikeType(type: Type): boolean;
64036419
getTypePredicateOfSignature(signature: Signature): TypePredicate | undefined;
64046420
/**
64056421
* Depending on the operation performed, it may be appropriate to throw away the checker

tests/baselines/reference/api/typescript.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,7 @@ declare namespace ts {
23352335
}
23362336
interface TypeChecker {
23372337
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
2338+
getTypeOfSymbol(symbol: Symbol): Type;
23382339
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
23392340
getPropertiesOfType(type: Type): Symbol[];
23402341
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
@@ -2425,6 +2426,21 @@ declare namespace ts {
24252426
getApparentType(type: Type): Type;
24262427
getBaseConstraintOfType(type: Type): Type | undefined;
24272428
getDefaultFromTypeParameter(type: Type): Type | undefined;
2429+
/**
2430+
* True if this type is the `Array` or `ReadonlyArray` type from lib.d.ts.
2431+
* This function will _not_ return true if passed a type which
2432+
* extends `Array` (for example, the TypeScript AST's `NodeArray` type).
2433+
*/
2434+
isArrayType(type: Type): boolean;
2435+
/**
2436+
* True if this type is a tuple type. This function will _not_ return true if
2437+
* passed a type which extends from a tuple.
2438+
*/
2439+
isTupleType(type: Type): boolean;
2440+
/**
2441+
* True if this type is assignable to `ReadonlyArray<any>`.
2442+
*/
2443+
isArrayLikeType(type: Type): boolean;
24282444
getTypePredicateOfSignature(signature: Signature): TypePredicate | undefined;
24292445
/**
24302446
* Depending on the operation performed, it may be appropriate to throw away the checker

0 commit comments

Comments
 (0)