cure53 / DOMPurify

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:
https://cure53.de/purify
Other
14.12k stars 733 forks source link

`type DOMPurify` is not exported #1020

Closed asamuzaK closed 1 week ago

asamuzaK commented 1 week ago

This issue proposes a [bug, feature] which...

Background & Context

With DOMPurify@3.2.0, I got the following error when creating d.ts of my project:

> npx tsc
src/mjs/dompurify.js:5:1 - error TS9006: Declaration emit for this file requires using private name 'DOMPurify' from module '"C:/Users/XXX/Documents/YYY/node_modules/dompurify/dist/purify.es"'. An explicit type annotation may unblock declaration emit.

5 import DOMPurify from 'dompurify';
  ~~~~~~

In dist/purify.es.d.mts, type DOMPurify is not exported.

dist/purify.es.d.mts#L399:

export { type Config, type Hook, type HookName, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike, _default as default };

Adding type DOMSelector to export {} fixed it.

dist/purify.es.d.mts#L399:

export { type Config, type DOMPurify, type Hook, type HookName, type RemovedAttribute, type RemovedElement, type UponSanitizeAttributeHook, type UponSanitizeAttributeHookEvent, type UponSanitizeElementHook, type UponSanitizeElementHookEvent, type WindowLike, _default as default };

Feature

I think this is because DOMPurify is not exported in src/purify.ts

src/purify.ts#L1680:

interface DOMPurify {
  ...
}

Add export should fix this.

src/purify.ts#L1680:

export interface DOMPurify {
  ...
}

I'll send a PR.

ghiscoding commented 1 week ago

Adding type DOMSelector to export {} fixed it.

I think you made a typo and meant type DOMPurify?

asamuzaK commented 1 week ago

Adding type DOMSelector to export {} fixed it.

I think you made a typo and meant type DOMPurify?

Yes, it's typo. I've already fixed the title. Thanks.