From 8fd440d9d0a4347f2e8715b21f3224c5df6518ca Mon Sep 17 00:00:00 2001 From: Oleksii Okadurin Date: Mon, 4 Mar 2024 09:45:59 +0100 Subject: [PATCH] fix(ui): type fixes ScopedElements --- .../core/src/ScopedElementsMixin.js | 2 ++ packages/ui/components/core/src/types.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/ui/components/core/src/types.ts diff --git a/packages/ui/components/core/src/ScopedElementsMixin.js b/packages/ui/components/core/src/ScopedElementsMixin.js index ea15025e7..24ac8fb4e 100644 --- a/packages/ui/components/core/src/ScopedElementsMixin.js +++ b/packages/ui/components/core/src/ScopedElementsMixin.js @@ -35,6 +35,7 @@ import { ScopedElementsMixin as OpenWcLitScopedElementsMixin } from '@open-wc/sc * @typedef {typeof import('lit').LitElement} TypeofLitElement * @typedef {import('@open-wc/dedupe-mixin').Constructor} LitElementConstructor * @typedef {import('@open-wc/dedupe-mixin').Constructor} ScopedElementsHostConstructor + * @typedef {import('./types.js').ScopedElementsHostV2Constructor} ScopedElementsHostV2Constructor */ const supportsScopedRegistry = Boolean( @@ -45,6 +46,7 @@ const supportsScopedRegistry = Boolean( /** * @template {LitElementConstructor} T * @param {T} superclass + * @return {T & ScopedElementsHostConstructor & ScopedElementsHostV2Constructor} */ const ScopedElementsMixinImplementation = superclass => /** @type {ScopedElementsHost} */ diff --git a/packages/ui/components/core/src/types.ts b/packages/ui/components/core/src/types.ts new file mode 100644 index 000000000..b8950d1a0 --- /dev/null +++ b/packages/ui/components/core/src/types.ts @@ -0,0 +1,19 @@ +// Note. This file is a partial copy of https://github.com/open-wc/open-wc/blob/scoped-elements-v2/packages/scoped-elements/src/types.d.ts + +import { Constructor } from '@open-wc/dedupe-mixin'; + +export declare class ScopedElementsHostV2 { + /** + * Defines a scoped element inside the CustomElementRegistry bound to the shadowRoot. + */ + defineScopedElement(tagName: string, klass: Constructor): void; + + /** + * Create a scoped element inside the CustomElementRegistry bound to the shadowRoot. + * + * @param tagName string The tag name of the element to create + */ + createScopedElement(tagName: string): HTMLElement; +} + +export type ScopedElementsHostV2Constructor = Constructor;