method-shorthand-jsdoc

Refactor JavaScript/TypeScript factory functions to preserve JSDoc using method shorthand.

4.7k|374|Updated Mar 16, 2023
One-click install
npx skills add https://github.com/EpicenterHQ/epicenter --skill method-shorthand-jsdoc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: method-shorthand-jsdoc
Source: https://github.com/EpicenterHQ/epicenter/tree/main/.agents/skills/method-shorthand-jsdoc
Command: npx skills add https://github.com/EpicenterHQ/epicenter --skill method-shorthand-jsdoc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When factory functions expose helpers that are only used by returned methods, JSDoc can be lost or not shown in IDE hover. This skill teaches moving internal helpers into the return object using method shorthand so documentation stays attached to the correct methods.

Core Features & Use Cases

  • Use method shorthand to expose internal helpers as methods on the returned object, ensuring JSDoc remains visible to consumers.
  • Supports scenarios where helper functions are only invoked by sibling methods and need to reference each other via this.
  • Applicable to JavaScript/TypeScript factory patterns to improve code readability and developer experience.

Quick Start

Identify a factory function with internal helpers and refactor by placing the helpers into the returned object using method shorthand to preserve inline documentation.

Frequently Asked Questions about method-shorthand-jsdoc

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I preserve JSDoc on methods returned by a JavaScript factory function?

To preserve JSDoc on methods returned by a factory function, move internal helper functions into the return object using method shorthand. This attaches inline documentation directly to the methods, ensuring proper IDE hover visibility for consumers.

Why does my IDE hover documentation disappear for helper functions inside a TypeScript factory pattern?

IDE hover documentation disappears because internal helpers are scoped outside the returned object. Inlining these helpers as method shorthand members within the return object ensures JSDoc remains visible and properly attached to the exposed methods.

What is the method shorthand refactor pattern for JavaScript factory functions?

The method shorthand refactor pattern transforms internal helper functions into properties of the returned object. This allows sibling methods to reference each other via this-calls while preserving inline JSDoc for both consumers and internal method calls.

Can I use this-calls between methods in a JavaScript factory function without losing JSDoc?

Yes, you can use this-calls between methods in a factory function without losing JSDoc by defining members with method shorthand. This enables sibling methods to invoke each other via this while maintaining accurate IDE hover documentation.

When should I inline helpers into a return object using method shorthand?

You should inline helpers into a return object using method shorthand when the helpers are used exclusively by returned methods in a JavaScript or TypeScript factory pattern. This approach improves code readability and preserves inline documentation.

Does refactoring internal helpers to method shorthand affect TypeScript type inference?

Refactoring internal helpers to method shorthand preserves TypeScript type inference within factory-style functions. By exposing helpers as methods on the returned object, the pattern maintains proper IDE hover documentation and enables seamless this-calls between methods.