Skip to content

docs: add TypeScript examples for typed hooks#159

Open
vittorioexp wants to merge 1 commit into
unjs:mainfrom
vittorioexp:docs/typescript-examples
Open

docs: add TypeScript examples for typed hooks#159
vittorioexp wants to merge 1 commit into
unjs:mainfrom
vittorioexp:docs/typescript-examples

Conversation

@vittorioexp

@vittorioexp vittorioexp commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • Add TypeScript examples for createHooks<T> and Hookable<T> to the README
  • Note that hook callbacks should return void / Promise<void> (return values from callHook are not the intended data channel)

Closes #33

Test plan

  • README examples match patterns in test/types.test.ts
  • Section renders correctly on GitHub

Summary by CodeRabbit

  • Documentation
    • Added TypeScript guidance for strongly typing hook names and callback arguments.
    • Included examples for typed createHooks usage and typed Hookable subclasses.
    • Clarified that hook callbacks should return void or Promise<void>, with data passed through callback arguments.

Closes unjs#33

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2314c9dc-e797-4e59-9f8e-23b215bafe49

📥 Commits

Reviewing files that changed from the base of the PR and between b77477c and e67cec1.

📒 Files selected for processing (1)
  • README.md

📝 Walkthrough

Walkthrough

The README adds a TypeScript section with typed createHooks and Hookable examples, and documents callback return types and passing data through hook arguments.

Changes

TypeScript documentation

Layer / File(s) Summary
Typed hook examples and callback guidance
README.md
Adds TypeScript examples for strongly typed hook interfaces with createHooks and generic Hookable subclasses, plus guidance for void or Promise<void> callbacks and hook arguments over callHook return values.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s README docs update for TypeScript typed hook examples.
Linked Issues check ✅ Passed The README additions cover typed createHooks/Hookable examples and clarify callbacks should return void or Promise, matching #33.
Out of Scope Changes check ✅ Passed The changes stay within documentation updates for typed hooks and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript Examples

1 participant