diff --git a/src/query.test.ts b/src/query.test.ts index ca64162..6d7aad0 100644 --- a/src/query.test.ts +++ b/src/query.test.ts @@ -30,6 +30,10 @@ describe('query', () => { const _el: QueriedElement<':scope'> = {} as Element; }); + typeTest('resolve `:scope` to `null` for `ShadowRoot`', () => { + const _el: QueriedElement<':scope', ShadowRoot> = null; + }); + typeTest('resolves a tag name with class', () => { const _el: HTMLInputElement = {} as QueriedElement<'input.clazz'>; }); @@ -117,6 +121,10 @@ describe('query', () => { typeTest('resolves queries without a tag name to `Element`', () => { const _el: QueriedElement<'.foo'> = {} as Element; }); + + typeTest('resolves queries from a `ShadowRoot`', () => { + const _el: QueriedElement<'input', ShadowRoot> = {} as HTMLInputElement; + }); }); }); diff --git a/src/query.ts b/src/query.ts index e87ccbe..c9eb19a 100644 --- a/src/query.ts +++ b/src/query.ts @@ -8,15 +8,17 @@ * return. * * @param Query The selector query to resolve. - * @param Host The host element making the query. + * @param Root The root element or shadow root making the query. * @returns A union of all possible {@link Element} objects which may be * returned by the query. */ export type QueriedElement< Query extends string, - Host extends Element = Element, + Root extends Element | ShadowRoot = Element, > = Query extends ':scope' - ? Host + ? Root extends Element + ? Root + : null : Union>>> ;