@@ -5165,7 +5165,7 @@ namespace ts {
5165
5165
// Appends the type parameters given by a list of declarations to a set of type parameters and returns the resulting set.
5166
5166
// The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set
5167
5167
// in-place and returns the same array.
5168
- function appendTypeParameters(typeParameters: TypeParameter[], declarations: ReadonlyArray<TypeParameterDeclaration>): TypeParameter[] {
5168
+ function appendTypeParameters(typeParameters: TypeParameter[] | undefined , declarations: ReadonlyArray<TypeParameterDeclaration>): TypeParameter[] {
5169
5169
for (const declaration of declarations) {
5170
5170
typeParameters = appendIfUnique(typeParameters, getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)));
5171
5171
}
@@ -5206,7 +5206,7 @@ namespace ts {
5206
5206
else if (node.kind === SyntaxKind.ConditionalType) {
5207
5207
return concatenate(outerTypeParameters, getInferTypeParameters(<ConditionalTypeNode>node));
5208
5208
}
5209
- const outerAndOwnTypeParameters = appendTypeParameters(outerTypeParameters, getEffectiveTypeParameterDeclarations(<DeclarationWithTypeParameters>node) || emptyArray );
5209
+ const outerAndOwnTypeParameters = appendTypeParameters(outerTypeParameters, getEffectiveTypeParameterDeclarations(<DeclarationWithTypeParameters>node));
5210
5210
const thisType = includeThisTypes &&
5211
5211
(node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.InterfaceDeclaration) &&
5212
5212
getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node)).thisType;
@@ -5224,17 +5224,14 @@ namespace ts {
5224
5224
// The local type parameters are the combined set of type parameters from all declarations of the class,
5225
5225
// interface, or type alias.
5226
5226
function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): TypeParameter[] {
5227
- let result: TypeParameter[];
5227
+ let result: TypeParameter[] | undefined ;
5228
5228
for (const node of symbol.declarations) {
5229
5229
if (node.kind === SyntaxKind.InterfaceDeclaration ||
5230
5230
node.kind === SyntaxKind.ClassDeclaration ||
5231
5231
node.kind === SyntaxKind.ClassExpression ||
5232
5232
isTypeAlias(node)) {
5233
5233
const declaration = <InterfaceDeclaration | TypeAliasDeclaration | JSDocTypedefTag | JSDocCallbackTag>node;
5234
- const typeParameters = getEffectiveTypeParameterDeclarations(declaration);
5235
- if (typeParameters) {
5236
- result = appendTypeParameters(result, typeParameters);
5237
- }
5234
+ result = appendTypeParameters(result, getEffectiveTypeParameterDeclarations(declaration));
5238
5235
}
5239
5236
}
5240
5237
return result;
@@ -5744,7 +5741,7 @@ namespace ts {
5744
5741
const typeParameters = getEffectiveTypeParameterDeclarations(node);
5745
5742
return (node.kind === SyntaxKind.Constructor || (returnType && isThislessType(returnType))) &&
5746
5743
node.parameters.every(isThislessVariableLikeDeclaration) &&
5747
- (! typeParameters || typeParameters .every(isThislessTypeParameter) );
5744
+ typeParameters.every(isThislessTypeParameter);
5748
5745
}
5749
5746
5750
5747
/**
@@ -7071,11 +7068,11 @@ namespace ts {
7071
7068
7072
7069
// Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual
7073
7070
// type checking functions).
7074
- function getTypeParametersFromDeclaration(declaration: DeclarationWithTypeParameters): TypeParameter[] {
7075
- let result: TypeParameter[];
7076
- forEach( getEffectiveTypeParameterDeclarations(declaration), node => {
7071
+ function getTypeParametersFromDeclaration(declaration: DeclarationWithTypeParameters): TypeParameter[] | undefined {
7072
+ let result: TypeParameter[] | undefined ;
7073
+ for (const node of getEffectiveTypeParameterDeclarations(declaration)) {
7077
7074
result = appendIfUnique(result, getDeclaredTypeOfTypeParameter(node.symbol));
7078
- });
7075
+ }
7079
7076
return result;
7080
7077
}
7081
7078
@@ -22679,7 +22676,7 @@ namespace ts {
22679
22676
// Only report errors on the last declaration for the type parameter container;
22680
22677
// this ensures that all uses have been accounted for.
22681
22678
const typeParameters = getEffectiveTypeParameterDeclarations(node);
22682
- if (!(node.flags & NodeFlags.Ambient) && typeParameters && last(getSymbolOfNode(node)!.declarations) === node) {
22679
+ if (!(node.flags & NodeFlags.Ambient) && last(getSymbolOfNode(node)!.declarations) === node) {
22683
22680
for (const typeParameter of typeParameters) {
22684
22681
if (!(getMergedSymbol(typeParameter.symbol).isReferenced & SymbolFlags.TypeParameter) && !isIdentifierThatStartsWithUnderScore(typeParameter.name)) {
22685
22682
addDiagnostic(UnusedKind.Parameter, createDiagnosticForNode(typeParameter.name, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolName(typeParameter.symbol)));
@@ -24047,7 +24044,7 @@ namespace ts {
24047
24044
/**
24048
24045
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
24049
24046
*/
24050
- function checkTypeParameters(typeParameterDeclarations: ReadonlyArray<TypeParameterDeclaration>) {
24047
+ function checkTypeParameters(typeParameterDeclarations: ReadonlyArray<TypeParameterDeclaration> | undefined ) {
24051
24048
if (typeParameterDeclarations) {
24052
24049
let seenDefault = false;
24053
24050
for (let i = 0; i < typeParameterDeclarations.length; i++) {
@@ -24103,7 +24100,7 @@ namespace ts {
24103
24100
for (const declaration of declarations) {
24104
24101
// If this declaration has too few or too many type parameters, we report an error
24105
24102
const sourceParameters = getEffectiveTypeParameterDeclarations(declaration);
24106
- const numTypeParameters = length( sourceParameters) ;
24103
+ const numTypeParameters = sourceParameters.length ;
24107
24104
if (numTypeParameters < minTypeArgumentCount || numTypeParameters > maxTypeArgumentCount) {
24108
24105
return false;
24109
24106
}
@@ -27371,7 +27368,7 @@ namespace ts {
27371
27368
}
27372
27369
}
27373
27370
27374
- function checkGrammarTypeParameterList(typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
27371
+ function checkGrammarTypeParameterList(typeParameters: NodeArray<TypeParameterDeclaration> | undefined , file: SourceFile): boolean {
27375
27372
if (typeParameters && typeParameters.length === 0) {
27376
27373
const start = typeParameters.pos - "<".length;
27377
27374
const end = skipTrivia(file.text, typeParameters.end) + ">".length;
@@ -27427,7 +27424,7 @@ namespace ts {
27427
27424
27428
27425
function checkGrammarClassLikeDeclaration(node: ClassLikeDeclaration): boolean {
27429
27426
const file = getSourceFileOfNode(node);
27430
- return checkGrammarClassDeclarationHeritageClauses(node) || checkGrammarTypeParameterList(getEffectiveTypeParameterDeclarations( node) , file);
27427
+ return checkGrammarClassDeclarationHeritageClauses(node) || checkGrammarTypeParameterList(node.typeParameters , file);
27431
27428
}
27432
27429
27433
27430
function checkGrammarArrowFunction(node: Node, file: SourceFile): boolean {
@@ -28199,8 +28196,8 @@ namespace ts {
28199
28196
28200
28197
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
28201
28198
const typeParameters = getEffectiveTypeParameterDeclarations(node);
28202
- if (typeParameters) {
28203
- const { pos, end } = isNodeArray( typeParameters) ? typeParameters : first(typeParameters) ;
28199
+ if (isNodeArray( typeParameters) ) {
28200
+ const { pos, end } = typeParameters;
28204
28201
return grammarErrorAtPos(node, pos, end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
28205
28202
}
28206
28203
}
0 commit comments