Skip to content

Commit

Permalink
fix: types for overload of SelectorObserver constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Feb 16, 2024
1 parent f223ee2 commit 0462e35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-pants-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sv443-network/userutils": patch
---

Fixed TS types for overload of SelectorObserver constructor
8 changes: 5 additions & 3 deletions lib/SelectorObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type SelectorObserverOptions = {
enableOnAddListener?: boolean;
};

export type SelectorObserverConstructorOptions = MutationObserverInit & SelectorObserverOptions;

/** Observes the children of the given element for changes */
export class SelectorObserver {
private enabled = false;
Expand All @@ -45,14 +47,14 @@ export class SelectorObserver {
* @param baseElementSelector The selector of the element to observe
* @param options Fine-tune what triggers the MutationObserver's checking function - `subtree` and `childList` are set to true by default
*/
constructor(baseElementSelector: string, options?: SelectorObserverOptions & MutationObserverInit)
constructor(baseElementSelector: string, options?: SelectorObserverConstructorOptions)
/**
* Creates a new SelectorObserver that will observe the children of the given base element for changes (only creation and deletion of elements by default)
* @param baseElement The element to observe
* @param options Fine-tune what triggers the MutationObserver's checking function - `subtree` and `childList` are set to true by default
*/
constructor(baseElement: Element, options?: SelectorObserverOptions)
constructor(baseElement: Element | string, options: SelectorObserverOptions = {}) {
constructor(baseElement: Element, options?: SelectorObserverConstructorOptions)
constructor(baseElement: Element | string, options: SelectorObserverConstructorOptions = {}) {
this.baseElement = baseElement;

this.listenerMap = new Map<string, SelectorListenerOptions[]>();
Expand Down

0 comments on commit 0462e35

Please sign in to comment.