Skip to content

Commit f12b97f

Browse files
committed
Exclude variable initializers
1 parent e8d2570 commit f12b97f

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12760,8 +12760,6 @@ namespace ts {
1276012760
}
1276112761

1276212762
function getSignatureFromDeclaration(declaration: SignatureDeclaration | JSDocSignature): Signature {
12763-
const signature = getSignatureOfTypeTag(declaration);
12764-
if (signature) return signature;
1276512763
const links = getNodeLinks(declaration);
1276612764
if (!links.resolvedSignature) {
1276712765
const parameters: Symbol[] = [];
@@ -12941,7 +12939,15 @@ namespace ts {
1294112939
continue;
1294212940
}
1294312941
}
12944-
result.push(getSignatureFromDeclaration(decl));
12942+
// If this is a function or method declaration, get the accurate minArgumentCount from the type tag, if present.
12943+
// If this is a variable or property declaration, apply the type tag to the target
12944+
// (getTypeForVariableLikeDeclaration()), not to the initializer.
12945+
result.push(
12946+
(!isFunctionExpressionOrArrowFunction(decl) &&
12947+
!isObjectLiteralMethod(decl) &&
12948+
getSignatureOfTypeTag(decl)) ||
12949+
getSignatureFromDeclaration(decl)
12950+
);
1294512951
}
1294612952
return result;
1294712953
}

tests/cases/conformance/jsdoc/checkJsdocTypeTag6.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,26 @@ function add2(a, b) { return a + b; }
2121
// TODO: Should be an error since signature doesn't match.
2222
/** @type {(a: number, b: number, c: number) => number} */
2323
function add3(a, b) { return a + b; }
24+
25+
// Confirm initializers are compatible.
26+
// They can't have more parameters than the target.
27+
28+
/** @type {() => void} */
29+
function func(more) {}
30+
31+
/** @type {() => void} */
32+
const variable = function (more) {};
33+
34+
/** @type {() => void} */
35+
const arrow = (more) => {};
36+
37+
({
38+
/** @type {() => void} */
39+
method(more) {},
40+
41+
/** @type {() => void} */
42+
prop: function (more) {},
43+
44+
/** @type {() => void} */
45+
arrow: (more) => {},
46+
});

0 commit comments

Comments
 (0)