Skip to content

feat: export hook-related TypeScript types (#427)#429

Merged
kkomelin merged 1 commit intomasterfrom
hook-types
Apr 29, 2026
Merged

feat: export hook-related TypeScript types (#427)#429
kkomelin merged 1 commit intomasterfrom
hook-types

Conversation

@kkomelin
Copy link
Copy Markdown
Owner

@kkomelin kkomelin commented Apr 29, 2026

Summary

  • Re-export hook-related TypeScript types (NodeHook, ElementHook, DocumentFragmentHook, UponSanitizeElementHook, UponSanitizeAttributeHook, HookName) plus adjacent surface types (Config, DOMPurify, RemovedAttribute, RemovedElement, UponSanitizeAttributeHookEvent, UponSanitizeElementHookEvent, WindowLike) from dompurify so consumers can type addHook callbacks without redeclaring the signatures.
  • Document the new types in the README with a copy-friendly example.
  • Bump version to 3.11.0 (minor - additive type-only public surface).

Closes #427

Test plan

  • pnpm typecheck clean (now also covers tests/)
  • pnpm lint clean
  • pnpm test - 12/12 passing, including new tests/types.test.ts smoke assertions for both src/index and src/browser entries
  • pnpm build - verified dist/index.d.ts and dist/browser.d.ts re-export all 13 type names; runtime dist/*.js correctly omits the type-only re-exports

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Exported TypeScript type definitions for DOMPurify configuration, hooks, and related types to improve type safety for developers.
  • Documentation

    • Added comprehensive README section for TypeScript users with examples of using exported types and hook callbacks.
  • Tests

    • Added type validation tests to ensure exported types integrate correctly with the API.

Re-export Config, DOMPurify, DocumentFragmentHook, ElementHook, HookName,
NodeHook, RemovedAttribute, RemovedElement, UponSanitizeAttributeHook,
UponSanitizeAttributeHookEvent, UponSanitizeElementHook,
UponSanitizeElementHookEvent, and WindowLike from dompurify so consumers
can type addHook callbacks without redeclaring the signatures.

Closes #427

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR exports TypeScript type definitions from the dompurify library through the main entry points (src/index.ts and src/browser.ts), allowing downstream consumers to reference official hook-related types instead of duplicating declarations locally. Documentation and tests validate the new exports.

Changes

Cohort / File(s) Summary
Type Re-exports
src/browser.ts, src/index.ts
Add type-only exports for DOMPurify types including Config, DOMPurify, hook-related types (NodeHook, ElementHook, DocumentFragmentHook, hook event types), and WindowLike to enable downstream consumers to use official type definitions.
Documentation
README.md
Add new section documenting re-exported hook-related types, including example usage of addHook with NodeHook type annotation and enumeration of all re-exported type aliases.
Testing
tests/types.test.ts
Introduce type-focused test suite validating that exported types are compatible with addHook, sanitize runtime, and re-exports across entry points; includes tests for hook registration, config object construction, and removed element/attribute union types.
Configuration & Metadata
package.json, tsconfig.json, biome.json
Bump package version to 3.11.0, update pnpm toolchain to 10.33.2, update Biome schema to 2.4.13, and expand tsconfig.json include to cover the new tests directory.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Types flow freely through the warren now,
No more duplication, just a hoppy vow,
Hooks and configs, exported with care,
TypeScript happiness fills the air!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: exporting hook-related TypeScript types, which is precisely what the PR delivers.
Linked Issues check ✅ Passed All required types from issue #427 are exported: HookName, NodeHook, ElementHook, DocumentFragmentHook, UponSanitizeElementHook, UponSanitizeAttributeHook, plus supporting types (Config, DOMPurify, RemovedAttribute, RemovedElement, UponSanitizeAttributeHookEvent, UponSanitizeElementHookEvent, WindowLike).
Out of Scope Changes check ✅ Passed Changes are appropriately scoped: type exports, documentation, version bump, and tests directly support issue #427. Minor updates to toolchain and config (biome.json, tsconfig.json, pnpm) are necessary housekeeping without scope creep.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hook-types

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@kkomelin kkomelin merged commit 0a57303 into master Apr 29, 2026
2 of 3 checks passed
@kkomelin kkomelin deleted the hook-types branch April 29, 2026 14:02
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.

Export hook-related TypeScript types used by addHook

1 participant