Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3449,7 +3449,7 @@ func (c *Checker) checkFunctionOrMethodDeclaration(node *ast.Node) {
c.checkSourceElement(body)
c.checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, c.getReturnTypeFromAnnotation(node))
if node.FunctionLikeData().FullSignature != nil {
if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil {
if c.getContextualCallSignature(c.removeMissingOrUndefinedType(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)), node) == nil {
Comment thread
jyx-07 marked this conversation as resolved.
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments)
}
}
Expand Down Expand Up @@ -10233,7 +10233,7 @@ func (c *Checker) checkFunctionExpressionOrObjectLiteralMethod(node *ast.Node, c
c.checkGrammarForGenerator(node)
}
if node.FunctionLikeData().FullSignature != nil {
if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil {
if c.getContextualCallSignature(c.removeMissingOrUndefinedType(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)), node) == nil {
c.error(node.FunctionLikeData().FullSignature, diagnostics.A_JSDoc_type_tag_on_a_function_must_have_a_signature_with_the_correct_number_of_arguments)
}
}
Expand Down Expand Up @@ -20188,7 +20188,7 @@ func (c *Checker) getReturnTypeFromAnnotation(declaration *ast.Node) *Type {

func (c *Checker) getSignatureOfFullSignatureType(node *ast.Node) *Signature {
if ast.IsInJSFile(node) && (ast.IsFunctionDeclaration(node) || ast.IsMethodDeclaration(node) || ast.IsFunctionExpressionOrArrowFunction(node)) && node.FunctionLikeData().FullSignature != nil {
return c.getSingleCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature))
return c.getSingleCallSignature(c.removeMissingOrUndefinedType(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)))
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/a.js(10,12): error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.


==== /a.js (1 errors) ====
/** @typedef {{ method?: (s: string) => number }} Example */

const example = {
/** @type {Example['method']} */
method(s) {
return s.length;
}
};

/** @type {Example['method']} */
~~~~~~~~~~~~~~~~~
!!! error TS8030: A JSDoc '@type' tag on a function must have a signature with the correct number of arguments.
function tooManyParams(s, extra) {
return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/jsdocOptionalMethodFullSignature.ts] ////

=== /a.js ===
/** @typedef {{ method?: (s: string) => number }} Example */

const example = {
>example : Symbol(example, Decl(a.js, 2, 5))

/** @type {Example['method']} */
method(s) {
>method : Symbol(method, Decl(a.js, 2, 17))
>s : Symbol(s, Decl(a.js, 4, 9))

return s.length;
>s.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
>s : Symbol(s, Decl(a.js, 4, 9))
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
}
};

/** @type {Example['method']} */
function tooManyParams(s, extra) {
>tooManyParams : Symbol(tooManyParams, Decl(a.js, 7, 2))
>s : Symbol(s, Decl(a.js, 10, 23))
>extra : Symbol(extra, Decl(a.js, 10, 25))

return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//// [tests/cases/compiler/jsdocOptionalMethodFullSignature.ts] ////

=== /a.js ===
/** @typedef {{ method?: (s: string) => number }} Example */

const example = {
>example : { method(s: string): number; }
>{ /** @type {Example['method']} */ method(s) { return s.length; }} : { method(s: string): number; }

/** @type {Example['method']} */
method(s) {
>method : (s: string) => number
>s : string

return s.length;
>s.length : number
>s : string
>length : number
}
};

/** @type {Example['method']} */
function tooManyParams(s, extra) {
>tooManyParams : (s: string) => number
>s : string
>extra : any

return 0;
>0 : 0
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @target: es2015
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: /a.js
/** @typedef {{ method?: (s: string) => number }} Example */

const example = {
/** @type {Example['method']} */
method(s) {
return s.length;
}
};

/** @type {Example['method']} */
function tooManyParams(s, extra) {
return 0;
}