Skip to content

TS2775 when using arrow function for type predicate #45919

Closed
@dckc

Description

@dckc

Bug Report

Our shop prefers arrow function style and JSDoc annotations. I've got a type predicate that works as a function declaration but as an arrow function, I get 2775

🔎 Search Terms

  • arrow function
  • type predicate
  • TS2775

🕗 Version & Regression Information

Version 4.2.3 (and whatever version the playground runs)

  • This is the behavior in every version I tried

⏯ Playground Link

error

💻 Code

// @ts-check

/**
 * @typedef {{ legs: number }} Animal
 */

/**
 * @typedef { Animal & { says: 'bark'}} Dog
 */

/**
 * @param {Animal} specimen
 * @returns { asserts specimen is Dog }
 */
export const canine = specimen => {
  if (/** @type { Dog } */ (specimen).says !== 'bark') throw TypeError();
  return undefined;
};

/** @param { string[] } argv */
export const main = argv => {
  /** @type { Animal } */
  const specimen1 = JSON.parse(argv[3]);
  canine(specimen1);
  console.log(specimen1.says);
};

🙁 Actual behavior

Assertions require every name in the call target to be declared with an explicit type annotation.(2775)

🙂 Expected behavior

same as when I change the arrow function to a function declaration:

no error

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions