Skip to content

Commit 7c22023

Browse files
authored
fix(52514): overload Tags do not receive noImplicitAny errors on missing return types (#52518)
1 parent 7f41c90 commit 7c22023

7 files changed

+139
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14446,7 +14446,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1444614446
if (node.tags) {
1444714447
for (const tag of node.tags) {
1444814448
if (isJSDocOverloadTag(tag)) {
14449-
result.push(getSignatureFromDeclaration(tag.typeExpression));
14449+
const jsDocSignature = tag.typeExpression;
14450+
if (jsDocSignature.type === undefined) {
14451+
reportImplicitAny(jsDocSignature, anyType);
14452+
}
14453+
result.push(getSignatureFromDeclaration(jsDocSignature));
1445014454
hasJSDocOverloads = true;
1445114455
}
1445214456
}
@@ -23419,6 +23423,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2341923423
case SyntaxKind.JSDocFunctionType:
2342023424
error(declaration, Diagnostics.Function_type_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString);
2342123425
return;
23426+
case SyntaxKind.JSDocSignature:
23427+
if (noImplicitAny && isJSDocOverloadTag(declaration.parent)) {
23428+
error(declaration.parent.tagName, Diagnostics.This_overload_implicitly_returns_the_type_0_because_it_lacks_a_return_type_annotation, typeAsString);
23429+
}
23430+
return;
2342223431
case SyntaxKind.FunctionDeclaration:
2342323432
case SyntaxKind.MethodDeclaration:
2342423433
case SyntaxKind.MethodSignature:

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,10 @@
62136213
"category": "Error",
62146214
"code": 7011
62156215
},
6216+
"This overload implicitly returns the type '{0}' because it lacks a return type annotation.": {
6217+
"category": "Error",
6218+
"code": 7012
6219+
},
62166220
"Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.": {
62176221
"category": "Error",
62186222
"code": 7013
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/a.js(2,5): error TS7012: This overload implicitly returns the type 'any' because it lacks a return type annotation.
2+
/a.js(7,5): error TS7012: This overload implicitly returns the type 'any' because it lacks a return type annotation.
3+
4+
5+
==== /a.js (2 errors) ====
6+
/**
7+
* @overload
8+
~~~~~~~~
9+
!!! error TS7012: This overload implicitly returns the type 'any' because it lacks a return type annotation.
10+
* @param {number} x
11+
*/
12+
13+
/**
14+
* @overload
15+
~~~~~~~~
16+
!!! error TS7012: This overload implicitly returns the type 'any' because it lacks a return type annotation.
17+
* @param {string} x
18+
*/
19+
20+
/**
21+
* @param {string | number} x
22+
* @returns {string | number}
23+
*/
24+
function id(x) {
25+
return x;
26+
}
27+
28+
export let a = id(123);
29+
export let b = id("hello");
30+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== /a.js ===
2+
/**
3+
* @overload
4+
* @param {number} x
5+
*/
6+
7+
/**
8+
* @overload
9+
* @param {string} x
10+
*/
11+
12+
/**
13+
* @param {string | number} x
14+
* @returns {string | number}
15+
*/
16+
function id(x) {
17+
>id : Symbol(id, Decl(a.js, 0, 0))
18+
>x : Symbol(x, Decl(a.js, 14, 12))
19+
20+
return x;
21+
>x : Symbol(x, Decl(a.js, 14, 12))
22+
}
23+
24+
export let a = id(123);
25+
>a : Symbol(a, Decl(a.js, 18, 10))
26+
>id : Symbol(id, Decl(a.js, 0, 0))
27+
28+
export let b = id("hello");
29+
>b : Symbol(b, Decl(a.js, 19, 10))
30+
>id : Symbol(id, Decl(a.js, 0, 0))
31+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== /a.js ===
2+
/**
3+
* @overload
4+
* @param {number} x
5+
*/
6+
7+
/**
8+
* @overload
9+
* @param {string} x
10+
*/
11+
12+
/**
13+
* @param {string | number} x
14+
* @returns {string | number}
15+
*/
16+
function id(x) {
17+
>id : { (x: number): any; (x: string): any; }
18+
>x : string | number
19+
20+
return x;
21+
>x : string | number
22+
}
23+
24+
export let a = id(123);
25+
>a : any
26+
>id(123) : any
27+
>id : { (x: number): any; (x: string): any; }
28+
>123 : 123
29+
30+
export let b = id("hello");
31+
>b : any
32+
>id("hello") : any
33+
>id : { (x: number): any; (x: string): any; }
34+
>"hello" : "hello"
35+

tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ Info 32 [00:01:13.000] response:
13631363
"6931",
13641364
"7009",
13651365
"7011",
1366+
"7012",
13661367
"7013",
13671368
"7014",
13681369
"7015",
@@ -2711,6 +2712,7 @@ Info 38 [00:01:19.000] response:
27112712
"6931",
27122713
"7009",
27132714
"7011",
2715+
"7012",
27142716
"7013",
27152717
"7014",
27162718
"7015",
@@ -3971,6 +3973,7 @@ Info 40 [00:01:21.000] response:
39713973
"6931",
39723974
"7009",
39733975
"7011",
3976+
"7012",
39743977
"7013",
39753978
"7014",
39763979
"7015",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @noImplicitAny: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noEmit: true
5+
// @filename: /a.js
6+
7+
/**
8+
* @overload
9+
* @param {number} x
10+
*/
11+
12+
/**
13+
* @overload
14+
* @param {string} x
15+
*/
16+
17+
/**
18+
* @param {string | number} x
19+
* @returns {string | number}
20+
*/
21+
function id(x) {
22+
return x;
23+
}
24+
25+
export let a = id(123);
26+
export let b = id("hello");

0 commit comments

Comments
 (0)