(node)
| 81870 | } |
| 81871 | } |
| 81872 | function checkFunctionOrMethodDeclaration(node) { |
| 81873 | var _a; |
| 81874 | checkDecorators(node); |
| 81875 | checkSignatureDeclaration(node); |
| 81876 | var functionFlags = ts.getFunctionFlags(node); |
| 81877 | // Do not use hasDynamicName here, because that returns false for well known symbols. |
| 81878 | // We want to perform checkComputedPropertyName for all computed properties, including |
| 81879 | // well known symbols. |
| 81880 | if (node.name && node.name.kind === 162 /* SyntaxKind.ComputedPropertyName */) { |
| 81881 | // This check will account for methods in class/interface declarations, |
| 81882 | // as well as accessors in classes/object literals |
| 81883 | checkComputedPropertyName(node.name); |
| 81884 | } |
| 81885 | if (hasBindableName(node)) { |
| 81886 | // first we want to check the local symbol that contain this declaration |
| 81887 | // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol |
| 81888 | // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode |
| 81889 | var symbol = getSymbolOfNode(node); |
| 81890 | var localSymbol = node.localSymbol || symbol; |
| 81891 | // Since the javascript won't do semantic analysis like typescript, |
| 81892 | // if the javascript file comes before the typescript file and both contain same name functions, |
| 81893 | // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function. |
| 81894 | var firstDeclaration = (_a = localSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find( |
| 81895 | // Get first non javascript function declaration |
| 81896 | function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 262144 /* NodeFlags.JavaScriptFile */); }); |
| 81897 | // Only type check the symbol once |
| 81898 | if (node === firstDeclaration) { |
| 81899 | checkFunctionOrConstructorSymbol(localSymbol); |
| 81900 | } |
| 81901 | if (symbol.parent) { |
| 81902 | // run check on export symbol to check that modifiers agree across all exported declarations |
| 81903 | checkFunctionOrConstructorSymbol(symbol); |
| 81904 | } |
| 81905 | } |
| 81906 | var body = node.kind === 168 /* SyntaxKind.MethodSignature */ ? undefined : node.body; |
| 81907 | checkSourceElement(body); |
| 81908 | checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, getReturnTypeFromAnnotation(node)); |
| 81909 | addLazyDiagnostic(checkFunctionOrMethodDeclarationDiagnostics); |
| 81910 | // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature |
| 81911 | if (ts.isInJSFile(node)) { |
| 81912 | var typeTag = ts.getJSDocTypeTag(node); |
| 81913 | if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { |
| 81914 | error(typeTag.typeExpression.type, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); |
| 81915 | } |
| 81916 | } |
| 81917 | function checkFunctionOrMethodDeclarationDiagnostics() { |
| 81918 | if (!ts.getEffectiveReturnTypeNode(node)) { |
| 81919 | // Report an implicit any error if there is no body, no explicit return type, and node is not a private method |
| 81920 | // in an ambient context |
| 81921 | if (ts.nodeIsMissing(body) && !isPrivateWithinAmbient(node)) { |
| 81922 | reportImplicitAny(node, anyType); |
| 81923 | } |
| 81924 | if (functionFlags & 1 /* FunctionFlags.Generator */ && ts.nodeIsPresent(body)) { |
| 81925 | // A generator with a body and no type annotation can still cause errors. It can error if the |
| 81926 | // yielded values have no common supertype, or it can give an implicit any error if it has no |
| 81927 | // yielded values. The only way to trigger these errors is to try checking its return type. |
| 81928 | getReturnTypeOfSignature(getSignatureFromDeclaration(node)); |
| 81929 | } |
no test coverage detected
searching dependent graphs…