Skip to content

In JS, return type of type reference in @type tag is ignored on function declarations. #25525

@ghost

Description

TypeScript Version: 3.0.0-dev.20180707

Code

/** @typedef {"a" | "b"} U */

/** @return {U} */
function f0() { return "a"; }

/** @type {() => U} */
function f1() { return "a"; }

/** @typedef {() => U} RetU */

/** @type {RetU} */
function f2() { return "a"; }

/** @type {RetU} */
const f3 = () => "a";

const x0 = f0();
const x1 = f1();
const x2 = f2();
const x3 = f3();

Expected behavior:

x0 through x3 are all of type "a" | "b".

Actual behavior:

x2 is of type string.

Noticed while reviewing #25486.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions