-
-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imp: improved types and utils #1014
Conversation
*/ | ||
const _removeAttribute = function (name, node) { | ||
const _removeAttribute = function (name: string, element: Element): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set the Node
type to Element
because it gives a type error, and rename it accordingly.
src/utils.ts
Outdated
function unapply<T>(func: (thisArg: any, ...args: any[]) => T) { | ||
return (thisArg: any, ...args: any[]): T => apply(func, thisArg, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's much clearer than Function
!
@@ -137,7 +133,7 @@ function cleanArray(array: any[]): any[] { | |||
* @param object - The object to be cloned. | |||
* @returns A new object that copies the original. | |||
*/ | |||
function clone<T extends object>(object: T): T { | |||
function clone<T extends Record<string, any>>(object: T): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I unified the object types to the Record
type.
d748150
to
757d02c
Compare
757d02c
to
fbd2ce8
Compare
Thanks a ton 🙂 @reduckted and @aloisklink who have worked on the initial PRs - do you see any blockers or all good? We will likely release DOMPurify 3.2.0 soon in case all is fine. |
Let me know if you find anything wrong or if I missed anything 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK. Just a lot of redundant JSDoc tags that are unnecessarily specifying the type.
src/utils.ts
Outdated
* @param object - The object to look up the getter function in its prototype chain. | ||
* @param prop - The property name for which to find the getter function. | ||
* @returns The getter function found in the prototype chain or a fallback function. | ||
* @param {T} object - The object to look up the getter function in its prototype chain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types do not need to be specified in the JSDoc comments. The type annotations define the type.
src/utils.ts
Outdated
@@ -134,10 +134,10 @@ function cleanArray(array: any[]): any[] { | |||
/** | |||
* Shallow clone an object | |||
* | |||
* @param object - The object to be cloned. | |||
* @returns A new object that copies the original. | |||
* @param {T} object - The object to be cloned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the types in the JSDoc comments here.
src/utils.ts
Outdated
@@ -116,10 +116,10 @@ function addToSet( | |||
/** | |||
* Clean up an array to harden against CSPP | |||
* | |||
* @param array - The array to be cleaned. | |||
* @returns The cleaned version of the array | |||
* @param {T[]} array - The array to be cleaned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the types in the JSDoc comments here.
src/utils.ts
Outdated
* @param array - The array containing elements to be added to the set. | ||
* @param transformCaseFunc - An optional function to transform the case of each element before adding to the set. | ||
* @returns The modified set with added elements. | ||
* @param {Record<string, any>} set - The set to which elements will be added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the types in the JSDoc comments here.
src/utils.ts
Outdated
} | ||
|
||
/** | ||
* Creates a new function that constructs an instance of the given constructor function with the provided arguments. | ||
* | ||
* @param func - The constructor function to be wrapped and called. | ||
* @returns A new function that constructs an instance of the given constructor function with the provided arguments. | ||
* @param {(...args: any[]) => T} func - The constructor function to be wrapped and called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the types in the JSDoc comments here.
src/purify.ts
Outdated
@@ -1810,17 +1827,17 @@ interface DOMPurify { | |||
* Remove a DOMPurify hook at a given entryPoint | |||
* (pops it from the stack of hooks if more are present) | |||
* | |||
* @param entryPoint entry point for the hook to remove | |||
* @return removed(popped) hook | |||
* @param {BasicHookName} entryPoint entry point for the hook to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types can be removed from the JSDoc comments here.
src/purify.ts
Outdated
*/ | ||
removeHook(entryPoint: BasicHookName): Hook | undefined; | ||
|
||
/** | ||
* Remove a DOMPurify hook at a given entryPoint | ||
* (pops it from the stack of hooks if more are present) | ||
* | ||
* @param entryPoint entry point for the hook to remove | ||
* @return removed(popped) hook | ||
* @param {'uponSanitizeElement'} entryPoint entry point for the hook to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types can be removed from the JSDoc comments here.
src/purify.ts
Outdated
@@ -1830,8 +1847,8 @@ interface DOMPurify { | |||
* Remove a DOMPurify hook at a given entryPoint | |||
* (pops it from the stack of hooks if more are present) | |||
* | |||
* @param entryPoint entry point for the hook to remove | |||
* @return removed(popped) hook | |||
* @param {'uponSanitizeAttribute'} entryPoint entry point for the hook to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types can be removed from the JSDoc comments here.
src/purify.ts
Outdated
@@ -1840,12 +1857,15 @@ interface DOMPurify { | |||
/** | |||
* Removes all DOMPurify hooks at a given entryPoint | |||
* | |||
* @param entryPoint entry point for the hooks to remove | |||
* @param {HookName} entryPoint entry point for the hooks to remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types can be removed from the JSDoc comments here.
src/purify.ts
Outdated
*/ | ||
removeHooks(entryPoint: HookName): void; | ||
|
||
/** | ||
* Removes all DOMPurify hooks. | ||
* | ||
* @returns {void} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSDoc comment should be redundant since the return type annotation indicates the method returns void. @cure53 , do you want all functions to have an @returns
JSDoc tag, even if they don't return a value?
@reduckted @cure53 Yes, let's remove the unnecessarily specified type of JSDoc again! I agree that after supporting typescript, we no longer need to specify types in the Jsdoc. |
96d598a
to
fd7af7e
Compare
I fixed it! |
Thanks a lot everyone 🙏 |
Summary
@cure53 👋
I'm very happy to announce that
DOMPurify
now supports direct types.I've improved some of the types and added
const assertion
for tighter control.I made additional improvements to
ts-doc
.