-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc @type tag optional parameters #48132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f81bf97
e8d2570
7e3e4e5
45558c5
9cffbfa
1e84bc9
8d705b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -8873,10 +8873,8 @@ namespace ts { | |||||||
return getReturnTypeOfSignature(getterSignature); | ||||||||
} | ||||||||
} | ||||||||
if (isInJSFile(declaration)) { | ||||||||
const type = getParameterTypeOfTypeTag(func, declaration); | ||||||||
if (type) return type; | ||||||||
} | ||||||||
const parameterTypeOfTypeTag = getParameterTypeOfTypeTag(func, declaration); | ||||||||
if (parameterTypeOfTypeTag) return parameterTypeOfTypeTag; | ||||||||
// Use contextual parameter type if one is available | ||||||||
const type = declaration.symbol.escapedName === InternalSymbolName.This ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); | ||||||||
if (type) { | ||||||||
|
@@ -12941,7 +12939,15 @@ namespace ts { | |||||||
continue; | ||||||||
} | ||||||||
} | ||||||||
result.push(getSignatureFromDeclaration(decl)); | ||||||||
// If this is a function or method declaration, get the accurate minArgumentCount from the @type tag, if present. | ||||||||
// If this is a variable or property declaration, apply the @type tag to it | ||||||||
// (getTypeForVariableLikeDeclaration()), not to the initializer. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would delete this. I tried rewording and I got
Suggested change
which is OK, but not that valuable to state explicitly. I'll leave it up to you whether you want to keep this, since I'm probably over-familiar with the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sandersn Thanks! I agree, as written the whole comment isn't that valuable ... I guess I was aiming to answer:
I've added a commit with an alternative rewording (based on your suggestions), but I'm very open to going with your preference! |
||||||||
result.push( | ||||||||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
(!isFunctionExpressionOrArrowFunction(decl) && | ||||||||
!isObjectLiteralMethod(decl) && | ||||||||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
getSignatureOfTypeTag(decl)) || | ||||||||
getSignatureFromDeclaration(decl) | ||||||||
); | ||||||||
} | ||||||||
return result; | ||||||||
} | ||||||||
|
@@ -12976,7 +12982,7 @@ namespace ts { | |||||||
else { | ||||||||
const type = signature.declaration && getEffectiveReturnTypeNode(signature.declaration); | ||||||||
let jsdocPredicate: TypePredicate | undefined; | ||||||||
if (!type && isInJSFile(signature.declaration)) { | ||||||||
if (!type) { | ||||||||
const jsdocSignature = getSignatureOfTypeTag(signature.declaration!); | ||||||||
if (jsdocSignature && signature !== jsdocSignature) { | ||||||||
jsdocPredicate = getTypePredicateOfSignature(jsdocSignature); | ||||||||
|
@@ -17206,8 +17212,7 @@ namespace ts { | |||||||
} | ||||||||
|
||||||||
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { | ||||||||
return (!isFunctionDeclaration(node) || isInJSFile(node) && !!getTypeForDeclarationFromJSDocComment(node)) && | ||||||||
(hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node)); | ||||||||
return hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node); | ||||||||
} | ||||||||
|
||||||||
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) { | ||||||||
|
@@ -17216,7 +17221,7 @@ namespace ts { | |||||||
} | ||||||||
|
||||||||
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration { | ||||||||
return (isInJSFile(func) && isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && | ||||||||
return (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && | ||||||||
isContextSensitiveFunctionLikeDeclaration(func); | ||||||||
} | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,9 @@ tests/cases/conformance/jsdoc/a.js(13,1): error TS2554: Expected 1 arguments, bu | |
g() // should error | ||
~~~ | ||
!!! error TS2554: Expected 1 arguments, but got 0. | ||
!!! related TS6210 tests/cases/conformance/jsdoc/a.js:5:12: An argument for 's' was not provided. | ||
!!! related TS6210 tests/cases/conformance/jsdoc/a.js:4:13: An argument for 's' was not provided. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error span change shows that re-using the signature isn't precisely correct. It's probably close enough, though, and it would take much more code to copy over the properties of the declared signature to the new signature. |
||
h() | ||
~~~ | ||
!!! error TS2554: Expected 1 arguments, but got 0. | ||
!!! related TS6210 tests/cases/conformance/jsdoc/a.js:8:12: An argument for 's' was not provided. | ||
!!! related TS6210 tests/cases/conformance/jsdoc/a.js:7:14: An argument for 's' was not provided. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.