From a2628c90884dac88c4459b556c1bdd4bd6939c0a Mon Sep 17 00:00:00 2001 From: Alexander T Date: Sun, 12 Apr 2020 11:45:09 +0300 Subject: [PATCH] fix(37242): add reference to return type for JSDocFunctionType --- src/compiler/utilitiesPublic.ts | 2 +- .../reference/asyncArrowFunction_allowJs.errors.txt | 8 +++++++- .../reference/jsdocFunction_missingReturn.errors.txt | 9 +++++++++ .../reference/jsdocFunction_missingReturn.symbols | 5 +++++ .../reference/jsdocFunction_missingReturn.types | 5 +++++ .../conformance/jsdoc/jsdocFunction_missingReturn.ts | 8 ++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/jsdocFunction_missingReturn.errors.txt create mode 100644 tests/baselines/reference/jsdocFunction_missingReturn.symbols create mode 100644 tests/baselines/reference/jsdocFunction_missingReturn.types create mode 100644 tests/cases/conformance/jsdoc/jsdocFunction_missingReturn.ts diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 4a07f2b0bd8..d38187b406a 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -769,7 +769,7 @@ namespace ts { const sig = find(type.members, isCallSignatureDeclaration); return sig && sig.type; } - if (isFunctionTypeNode(type)) { + if (isFunctionTypeNode(type) || isJSDocFunctionType(type)) { return type.type; } } diff --git a/tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt b/tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt index 6c8d0c370d2..e006f1668c1 100644 --- a/tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction_allowJs.errors.txt @@ -1,11 +1,13 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(3,17): error TS2322: Type '0' is not assignable to type 'string'. +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 type. tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(7,23): error TS2322: Type '0' is not assignable to type 'string'. +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 type. tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(12,2): error TS2322: Type '0' is not assignable to type 'string'. tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(19,3): error TS2345: Argument of type '() => Promise' is not assignable to parameter of type '() => string'. Type 'Promise' is not assignable to type 'string'. -==== tests/cases/conformance/async/es2017/asyncArrowFunction/file.js (4 errors) ==== +==== tests/cases/conformance/async/es2017/asyncArrowFunction/file.js (6 errors) ==== // Error (good) /** @type {function(): string} */ const a = () => 0 @@ -14,12 +16,16 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(19,3): error TS2 // Error (good) /** @type {function(): string} */ + ~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. const b = async () => 0 ~ !!! error TS2322: Type '0' is not assignable to type 'string'. // No error (bad) /** @type {function(): string} */ + ~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise type. const c = async () => { return 0 ~~~~~~~~ diff --git a/tests/baselines/reference/jsdocFunction_missingReturn.errors.txt b/tests/baselines/reference/jsdocFunction_missingReturn.errors.txt new file mode 100644 index 00000000000..646e03fcd6f --- /dev/null +++ b/tests/baselines/reference/jsdocFunction_missingReturn.errors.txt @@ -0,0 +1,9 @@ +/a.js(1,24): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. + + +==== /a.js (1 errors) ==== + /** @type {function(): number} */ + ~~~~~~ +!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. + function f() {} + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocFunction_missingReturn.symbols b/tests/baselines/reference/jsdocFunction_missingReturn.symbols new file mode 100644 index 00000000000..85f75e30f29 --- /dev/null +++ b/tests/baselines/reference/jsdocFunction_missingReturn.symbols @@ -0,0 +1,5 @@ +=== /a.js === +/** @type {function(): number} */ +function f() {} +>f : Symbol(f, Decl(a.js, 0, 0)) + diff --git a/tests/baselines/reference/jsdocFunction_missingReturn.types b/tests/baselines/reference/jsdocFunction_missingReturn.types new file mode 100644 index 00000000000..ce3453a4a8c --- /dev/null +++ b/tests/baselines/reference/jsdocFunction_missingReturn.types @@ -0,0 +1,5 @@ +=== /a.js === +/** @type {function(): number} */ +function f() {} +>f : () => number + diff --git a/tests/cases/conformance/jsdoc/jsdocFunction_missingReturn.ts b/tests/cases/conformance/jsdoc/jsdocFunction_missingReturn.ts new file mode 100644 index 00000000000..1d3e938cda8 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocFunction_missingReturn.ts @@ -0,0 +1,8 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @strict: true + +// @Filename: /a.js +/** @type {function(): number} */ +function f() {}