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

Function getTypeFromJSDocVariadicType

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

Source from the content-addressed store, hash-verified

85819 }
85820 }
85821 function getTypeFromJSDocVariadicType(node) {
85822 var type = getTypeFromTypeNode(node.type);
85823 var parent = node.parent;
85824 var paramTag = node.parent.parent;
85825 if (ts.isJSDocTypeExpression(node.parent) && ts.isJSDocParameterTag(paramTag)) {
85826 // Else we will add a diagnostic, see `checkJSDocVariadicType`.
85827 var host_1 = ts.getHostSignatureFromJSDoc(paramTag);
85828 var isCallbackTag = ts.isJSDocCallbackTag(paramTag.parent.parent);
85829 if (host_1 || isCallbackTag) {
85830 /*
85831 Only return an array type if the corresponding parameter is marked as a rest parameter, or if there are no parameters.
85832 So in the following situation we will not create an array type:
85833 /** @param {...number} a * /
85834 function f(a) {}
85835 Because `a` will just be of type `number | undefined`. A synthetic `...args` will also be added, which *will* get an array type.
85836 */
85837 var lastParamDeclaration = isCallbackTag
85838 ? ts.lastOrUndefined(paramTag.parent.parent.typeExpression.parameters)
85839 : ts.lastOrUndefined(host_1.parameters);
85840 var symbol = ts.getParameterSymbolFromJSDoc(paramTag);
85841 if (!lastParamDeclaration ||
85842 symbol && lastParamDeclaration.symbol === symbol && ts.isRestParameter(lastParamDeclaration)) {
85843 return createArrayType(type);
85844 }
85845 }
85846 }
85847 if (ts.isParameter(parent) && ts.isJSDocFunctionType(parent.parent)) {
85848 return createArrayType(type);
85849 }
85850 return addOptionality(type);
85851 }
85852 // Function and class expression bodies are checked after all statements in the enclosing body. This is
85853 // to ensure constructs like the following are permitted:
85854 // const foo = function () {

Callers 1

Calls 3

getTypeFromTypeNodeFunction · 0.85
createArrayTypeFunction · 0.85
addOptionalityFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…