Skip to content

Commit b40bc0c

Browse files
author
Kanchalai Tanglertsampan
committed
Add type alias for TypeReferenceType and convert to use JSDoc
1 parent 23b2545 commit b40bc0c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6696,8 +6696,10 @@ namespace ts {
66966696
return length(type.target.typeParameters);
66976697
}
66986698

6699-
// Get type from reference to class or interface
6700-
function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol, typeArgs: Type[]): Type {
6699+
/**
6700+
* Get type from type-reference that reference to class or interface
6701+
*/
6702+
function getTypeFromClassOrInterfaceReference(node: TypeReferenceType, symbol: Symbol, typeArgs: Type[]): Type {
67016703
const type = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(symbol));
67026704
const typeParameters = type.localTypeParameters;
67036705
if (typeParameters) {
@@ -6738,10 +6740,12 @@ namespace ts {
67386740
return instantiation;
67396741
}
67406742

6741-
// Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include
6742-
// references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the
6743-
// declared type. Instantiations are cached using the type identities of the type arguments as the key.
6744-
function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol, typeArguments: Type[]): Type {
6743+
/**
6744+
* Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include
6745+
* references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the
6746+
* declared type. Instantiations are cached using the type identities of the type arguments as the key.
6747+
*/
6748+
function getTypeFromTypeAliasReference(node: TypeReferenceType, symbol: Symbol, typeArguments: Type[]): Type {
67456749
const type = getDeclaredTypeOfSymbol(symbol);
67466750
const typeParameters = getSymbolLinks(symbol).typeParameters;
67476751
if (typeParameters) {
@@ -6766,16 +6770,18 @@ namespace ts {
67666770
return type;
67676771
}
67686772

6769-
// Get type from reference to named type that cannot be generic (enum or type parameter)
6770-
function getTypeFromNonGenericTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type {
6773+
/**
6774+
* Get type from reference to named type that cannot be generic (enum or type parameter)
6775+
*/
6776+
function getTypeFromNonGenericTypeReference(node: TypeReferenceType, symbol: Symbol): Type {
67716777
if (node.typeArguments) {
67726778
error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
67736779
return unknownType;
67746780
}
67756781
return getDeclaredTypeOfSymbol(symbol);
67766782
}
67776783

6778-
function getTypeReferenceName(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): EntityNameOrEntityNameExpression | undefined {
6784+
function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined {
67796785
switch (node.kind) {
67806786
case SyntaxKind.TypeReference:
67816787
return (<TypeReferenceNode>node).typeName;
@@ -6803,7 +6809,7 @@ namespace ts {
68036809
return resolveEntityName(typeReferenceName, SymbolFlags.Type) || unknownSymbol;
68046810
}
68056811

6806-
function getTypeReferenceType(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol) {
6812+
function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) {
68076813
const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced.
68086814

68096815
if (symbol === unknownSymbol) {
@@ -6862,7 +6868,7 @@ namespace ts {
68626868
return strictNullChecks ? getUnionType([type, nullType]) : type;
68636869
}
68646870

6865-
function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type {
6871+
function getTypeFromTypeReference(node: TypeReferenceType): Type {
68666872
const links = getNodeLinks(node);
68676873
if (!links.resolvedType) {
68686874
let symbol: Symbol;
@@ -6893,7 +6899,7 @@ namespace ts {
68936899
return links.resolvedType;
68946900
}
68956901

6896-
function typeArgumentsFromTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type[] {
6902+
function typeArgumentsFromTypeReferenceNode(node: TypeReferenceType): Type[] {
68976903
return map(node.typeArguments, getTypeFromTypeNode);
68986904
}
68996905

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,8 @@ namespace ts {
892892
kind: SyntaxKind.ConstructorType;
893893
}
894894

895+
export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference;
896+
895897
export interface TypeReferenceNode extends TypeNode {
896898
kind: SyntaxKind.TypeReference;
897899
typeName: EntityName;

0 commit comments

Comments
 (0)