callback-this-type

Document and enforce the this context in callback APIs.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill callback-this-type
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: callback-this-type
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/callback-this-type
Command: npx skills add https://github.com/luyi985/lyi-bash --skill callback-this-type

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Document and enforce the this context in callback APIs.

Core Features & Use Cases

  • Typing this as the first parameter to callbacks to document API context
  • Improve autocompletion for event handlers and library callbacks
  • Clarify the intended runtime behavior by making this explicit

Quick Start

Annotate callback signatures with an explicit this parameter to specify the expected context.

Frequently Asked Questions about callback-this-type

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

FAQPage Schema
How do I type the this context in TypeScript callback APIs?

To type the this context in TypeScript callbacks, annotate the callback signature with an explicit this parameter as the first argument to specify the expected runtime context. This enforces proper typing and clarifies intended behavior for event handlers.

What is an explicit this parameter in TypeScript event handlers?

An explicit this parameter in TypeScript event handlers is a typed first parameter in a callback signature that documents the API context. It specifies the runtime this value passed to the callback, improving autocompletion and clarifying intended library behavior.

How do I improve autocompletion for library callbacks passing a specific this value?

Improve autocompletion for library callbacks by annotating the callback signature with an explicit this parameter. This documents the specific this value passed by the API, enabling TypeScript to provide accurate context-aware suggestions for event handlers.

Can I document and enforce the this context in user code callbacks without classes?

Yes, you can enforce the this context in user code callbacks without classes by defining an explicit this parameter in the callback signature. This makes the API context explicit and ensures proper typing regardless of the calling pattern.

When do I need to specify the this type for callback functions in TypeScript?

Specify the this type for callback functions in TypeScript when libraries or user code pass a specific this value to callbacks, such as in event handlers. This ensures proper typing, autocompletion, and documents the intended runtime context behavior.