From 91679e5f4d06087cafe943b779c53cbdc8633b30 Mon Sep 17 00:00:00 2001 From: Sjoerd Mulder Date: Tue, 6 Aug 2024 15:49:45 +0200 Subject: [PATCH] Add TypeScript support for Container.contains (#4471) * Adding contains method * Fix for typescript issue * Update preact.tsx * Update preact.tsx --- src/diff/children.js | 1 - src/index.d.ts | 1 + test/ts/preact.tsx | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diff/children.js b/src/diff/children.js index 93064c37dd..e50ca1cef5 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -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); diff --git a/src/index.d.ts b/src/index.d.ts index 269e242bfb..6a0a8f7853 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -293,6 +293,7 @@ interface ContainerNode { readonly firstChild: ContainerNode | null; readonly childNodes: ArrayLike; + contains(other: ContainerNode | null): boolean; insertBefore(node: ContainerNode, child: ContainerNode | null): ContainerNode; appendChild(node: ContainerNode): ContainerNode; removeChild(child: ContainerNode): ContainerNode; diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index bbc905d541..3713f9d8f5 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -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) {