Skip to content

Commit 3b222fe

Browse files
sandersnashyamanningneuhelos
authored
Shrink error span on @type errors for signatures (#42024)
Previously, the error span was too large on @type errors on functions when the type was not a function. The span covered the entire tag. This PR changes the error node just to be the type of the type tag. In other words, the error span was previously this: ``` @type {IncorrectType} ``` But is now just this: ``` IncorrectType ``` Fixes the first error from #41974, but not the other two. Co-authored-by: Ashya Manning <[email protected]> Co-authored-by: Nilber Remon <[email protected]> Co-authored-by: Ashya Manning <[email protected]> Co-authored-by: Nilber Remon <[email protected]>
1 parent 303ed3a commit 3b222fe

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33382,7 +33382,7 @@ namespace ts {
3338233382
if (isInJSFile(node)) {
3338333383
const typeTag = getJSDocTypeTag(node);
3338433384
if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) {
33385-
error(typeTag, Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature);
33385+
error(typeTag.typeExpression.type, Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature);
3338633386
}
3338733387
}
3338833388
}

tests/baselines/reference/checkJsdocTypeTag5.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tests/cases/conformance/jsdoc/test.js(7,24): error TS2322: Type 'number' is not
44
tests/cases/conformance/jsdoc/test.js(10,17): error TS2322: Type 'number' is not assignable to type 'string'.
55
tests/cases/conformance/jsdoc/test.js(12,14): error TS2322: Type 'number' is not assignable to type 'string'.
66
tests/cases/conformance/jsdoc/test.js(14,24): error TS2322: Type 'number' is not assignable to type 'string'.
7-
tests/cases/conformance/jsdoc/test.js(28,5): error TS8030: The type of a function declaration must match the function's signature.
7+
tests/cases/conformance/jsdoc/test.js(28,12): error TS8030: The type of a function declaration must match the function's signature.
88
tests/cases/conformance/jsdoc/test.js(34,5): error TS2322: Type '1 | 2' is not assignable to type '2 | 3'.
99
Type '1' is not assignable to type '2 | 3'.
1010

@@ -50,7 +50,7 @@ tests/cases/conformance/jsdoc/test.js(34,5): error TS2322: Type '1 | 2' is not a
5050
/** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */
5151

5252
/** @type {Gioconda} */
53-
~~~~~~~~~~~~~~~~
53+
~~~~~~~~
5454
!!! error TS8030: The type of a function declaration must match the function's signature.
5555
function monaLisa(sb) {
5656
return typeof sb === 'string' ? 1 : 2;

tests/baselines/reference/checkJsdocTypeTag6.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/conformance/jsdoc/test.js(1,5): error TS8030: The type of a function declaration must match the function's signature.
1+
tests/cases/conformance/jsdoc/test.js(1,12): error TS8030: The type of a function declaration must match the function's signature.
22
tests/cases/conformance/jsdoc/test.js(7,5): error TS2741: Property 'prop' is missing in type '(prop: any) => void' but required in type '{ prop: string; }'.
3-
tests/cases/conformance/jsdoc/test.js(10,5): error TS8030: The type of a function declaration must match the function's signature.
3+
tests/cases/conformance/jsdoc/test.js(10,12): error TS8030: The type of a function declaration must match the function's signature.
44

55

66
==== tests/cases/conformance/jsdoc/test.js (3 errors) ====
77
/** @type {number} */
8-
~~~~~~~~~~~~~~
8+
~~~~~~
99
!!! error TS8030: The type of a function declaration must match the function's signature.
1010
function f() {
1111
return 1
@@ -19,7 +19,7 @@ tests/cases/conformance/jsdoc/test.js(10,5): error TS8030: The type of a functio
1919
}
2020

2121
/** @type {(a: number) => number} */
22-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
~~~~~~~~~~~~~~~~~~~~~
2323
!!! error TS8030: The type of a function declaration must match the function's signature.
2424
function add1(a, b) { return a + b; }
2525

tests/baselines/reference/typeTagCircularReferenceOnConstructorFunction.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/conformance/jsdoc/bug27346.js(2,4): error TS8030: The type of a function declaration must match the function's signature.
1+
tests/cases/conformance/jsdoc/bug27346.js(2,11): error TS8030: The type of a function declaration must match the function's signature.
22

33

44
==== tests/cases/conformance/jsdoc/bug27346.js (1 errors) ====
55
/**
66
* @type {MyClass}
7-
~~~~~~~~~~~~~~~
7+
~~~~~~~
88
!!! error TS8030: The type of a function declaration must match the function's signature.
99
*/
1010
function MyClass() { }

0 commit comments

Comments
 (0)