MCPcopy Index your code
hub / github.com/nodejs/node / checkGrammarIndexSignatureParameters

Function checkGrammarIndexSignatureParameters

test/fixtures/snapshot/typescript.js:88122–88159  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

88120 return startLine !== endLine && grammarErrorOnNode(equalsGreaterThanToken, ts.Diagnostics.Line_terminator_not_permitted_before_arrow);
88121 }
88122 function checkGrammarIndexSignatureParameters(node) {
88123 var parameter = node.parameters[0];
88124 if (node.parameters.length !== 1) {
88125 if (parameter) {
88126 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
88127 }
88128 else {
88129 return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
88130 }
88131 }
88132 checkGrammarForDisallowedTrailingComma(node.parameters, ts.Diagnostics.An_index_signature_cannot_have_a_trailing_comma);
88133 if (parameter.dotDotDotToken) {
88134 return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
88135 }
88136 if (ts.hasEffectiveModifiers(parameter)) {
88137 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
88138 }
88139 if (parameter.questionToken) {
88140 return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
88141 }
88142 if (parameter.initializer) {
88143 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
88144 }
88145 if (!parameter.type) {
88146 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
88147 }
88148 var type = getTypeFromTypeNode(parameter.type);
88149 if (someType(type, function (t) { return !!(t.flags & 8576 /* TypeFlags.StringOrNumberLiteralOrUnique */); }) || isGenericType(type)) {
88150 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead);
88151 }
88152 if (!everyType(type, isValidIndexKeyType)) {
88153 return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type);
88154 }
88155 if (!node.type) {
88156 return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
88157 }
88158 return false;
88159 }
88160 function checkGrammarIndexSignature(node) {
88161 // Prevent cascading error by short-circuit
88162 return checkGrammarDecoratorsAndModifiers(node) || checkGrammarIndexSignatureParameters(node);

Callers 1

Calls 6

grammarErrorOnNodeFunction · 0.85
getTypeFromTypeNodeFunction · 0.85
someTypeFunction · 0.85
isGenericTypeFunction · 0.85
everyTypeFunction · 0.85

Tested by

no test coverage detected