Skip to content

Commit

Permalink
Add TypeScript support for Container.contains (#4471)
Browse files Browse the repository at this point in the history
* Adding contains method

* Fix for typescript issue

* Update preact.tsx

* Update preact.tsx
  • Loading branch information
sjoerdmulder authored Aug 6, 2024
1 parent ab743a9 commit 91679e5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ function insert(parentVNode, oldDom, parentDom) {
if (
oldDom &&
parentVNode.type &&
// @ts-expect-error olDom should be present on a DOM node
!parentDom.contains(oldDom)
) {
oldDom = getDomSibling(parentVNode);
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ interface ContainerNode {
readonly firstChild: ContainerNode | null;
readonly childNodes: ArrayLike<ContainerNode>;

contains(other: ContainerNode | null): boolean;
insertBefore(node: ContainerNode, child: ContainerNode | null): ContainerNode;
appendChild(node: ContainerNode): ContainerNode;
removeChild(child: ContainerNode): ContainerNode;
Expand Down
1 change: 1 addition & 0 deletions test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function createRootFragment(parent: Element, replaceNode: Element | Element[]) {
parentNode: parent,
firstChild: replaceNodes[0],
childNodes: replaceNodes,
contains: (c: Node) => parent.contains(c),
insertBefore: insert,
appendChild: (c: Node) => insert(c, null),
removeChild: function (c: Node) {
Expand Down

0 comments on commit 91679e5

Please sign in to comment.