Skip to content

Commit 9c1157a

Browse files
authored
fix(37242): add reference to return type for JSDocFunctionType (microsoft#37911)
2 parents 547fd12 + a2628c9 commit 9c1157a

6 files changed

+35
-2
lines changed

src/compiler/utilitiesPublic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ namespace ts {
769769
const sig = find(type.members, isCallSignatureDeclaration);
770770
return sig && sig.type;
771771
}
772-
if (isFunctionTypeNode(type)) {
772+
if (isFunctionTypeNode(type) || isJSDocFunctionType(type)) {
773773
return type.type;
774774
}
775775
}

tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(3,17): error TS2322: Type '0' is not assignable to type 'string'.
2+
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(6,24): error TS1064: The return type of an async function or method must be the global Promise<T> type.
23
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(7,23): error TS2322: Type '0' is not assignable to type 'string'.
4+
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(10,24): error TS1064: The return type of an async function or method must be the global Promise<T> type.
35
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(12,2): error TS2322: Type '0' is not assignable to type 'string'.
46
tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(19,3): error TS2345: Argument of type '() => Promise<number>' is not assignable to parameter of type '() => string'.
57
Type 'Promise<number>' is not assignable to type 'string'.
68

79

8-
==== tests/cases/conformance/async/es2017/asyncArrowFunction/file.js (4 errors) ====
10+
==== tests/cases/conformance/async/es2017/asyncArrowFunction/file.js (6 errors) ====
911
// Error (good)
1012
/** @type {function(): string} */
1113
const a = () => 0
@@ -14,12 +16,16 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(19,3): error TS2
1416

1517
// Error (good)
1618
/** @type {function(): string} */
19+
~~~~~~
20+
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
1721
const b = async () => 0
1822
~
1923
!!! error TS2322: Type '0' is not assignable to type 'string'.
2024

2125
// No error (bad)
2226
/** @type {function(): string} */
27+
~~~~~~
28+
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type.
2329
const c = async () => {
2430
return 0
2531
~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/a.js(1,24): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
2+
3+
4+
==== /a.js (1 errors) ====
5+
/** @type {function(): number} */
6+
~~~~~~
7+
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
8+
function f() {}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== /a.js ===
2+
/** @type {function(): number} */
3+
function f() {}
4+
>f : Symbol(f, Decl(a.js, 0, 0))
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== /a.js ===
2+
/** @type {function(): number} */
3+
function f() {}
4+
>f : () => number
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @strict: true
5+
6+
// @Filename: /a.js
7+
/** @type {function(): number} */
8+
function f() {}

0 commit comments

Comments
 (0)