-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generationEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Milestone
Description
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
💻 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:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generationEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this