Skip to content

@typedef jsdoc comment affects a functions ability to infer parameter types.Β #48179

@jespertheend

Description

@jespertheend

Bug Report

πŸ”Ž Search Terms

jsdoc infer function return any

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

/**
 * @template T
 * @typedef {T extends boolean ? T : T} ConvertPuppeteerArgument
 */

// Uncomment the next line in order to fix the issue:
// {}

/**
 * @template A
 * @template R
 * @param {(arg: ConvertPuppeteerArgument<A>) => R} fn
 * @param {A} arg
 */
export function runFunction(fn, arg) {
    return /** @type {R} */ ({});
}

const returnedValue = runFunction((str) => true, "str");
returnedValue; // `any`, but should be `boolean`

πŸ™ Actual behavior

returnedValue has the type any

πŸ™‚ Expected behavior

returnedValue has the type boolean, because the equivalent TypeScript also functions this way.
Furthermore, adding {} in between the two jsdoc comments fixes the issue, having extra jsdoc comments above a function should not affect its return value.

Possible duplicate: #43913, although I haven't been able to reduce this test case further to something like in that issue, so this might be caused by something else.

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions