Skip to content

popover target related attributes are not being recognized by TypeScript #228

@thescientist13

Description

@thescientist13

Current State

<button
  popovertarget="mobile-menu"
  popovertargetaction="hide"
>
  Close
</button>
Image

Desired State

No TS errors!

Although it feels like this should already be handed by TS, an interim solution seems to be to keep extending our custom JSX definition

// create a utility type to extract the attributes from any given element's DOM interface.
type ElementAttributes<E extends HTMLElement> = {
  // Extract all properties from the element, including inherited ones.
  [A in keyof E]?: E[A] extends (...args: any) => any ? any : IsCSSStyleDeclaration<E[A]>;
} & {
  class?: string;
  // add these
  popovertarget?: string;
  popovertargetaction?: 'show' | 'hide' | 'toggle';
};

Additional Context

I've been struggling to find an explanation for this, or if it's just something missing from TS, but can see the issue in action in #222 .

Here are the relevant MDN docs for reference
https://developer.mozilla.org/en-US/docs/Web/API/Popover_API

Metadata

Metadata

Labels

0.20.0documentationImprovements or additions to the website and / or documentationenhancementImprovement to existing functionalitytypes

Projects

Status

✅ Done

Relationships

None yet

Development

No branches or pull requests

Issue actions