Skip to content

Commit 91679e5

Browse files
authored
Add TypeScript support for Container.contains (#4471)
* Adding contains method * Fix for typescript issue * Update preact.tsx * Update preact.tsx
1 parent ab743a9 commit 91679e5

File tree

3 files changed

+2
-1
lines changed

3 files changed

+2
-1
lines changed

src/diff/children.js

-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ function insert(parentVNode, oldDom, parentDom) {
373373
if (
374374
oldDom &&
375375
parentVNode.type &&
376-
// @ts-expect-error olDom should be present on a DOM node
377376
!parentDom.contains(oldDom)
378377
) {
379378
oldDom = getDomSibling(parentVNode);

src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ interface ContainerNode {
293293
readonly firstChild: ContainerNode | null;
294294
readonly childNodes: ArrayLike<ContainerNode>;
295295

296+
contains(other: ContainerNode | null): boolean;
296297
insertBefore(node: ContainerNode, child: ContainerNode | null): ContainerNode;
297298
appendChild(node: ContainerNode): ContainerNode;
298299
removeChild(child: ContainerNode): ContainerNode;

test/ts/preact.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function createRootFragment(parent: Element, replaceNode: Element | Element[]) {
9797
parentNode: parent,
9898
firstChild: replaceNodes[0],
9999
childNodes: replaceNodes,
100+
contains: (c: Node) => parent.contains(c),
100101
insertBefore: insert,
101102
appendChild: (c: Node) => insert(c, null),
102103
removeChild: function (c: Node) {

0 commit comments

Comments
 (0)