Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ type ElementAttributes<E extends HTMLElement> = {
[A in keyof E]?: E[A] extends (...args: any) => any ? any : IsCSSStyleDeclaration<E[A]>;
} & {
class?: string;
};

type PopoverTargetAction = 'show' | 'hide' | 'toggle';
type PopoverTargetAttributes = {
// have to manage this manually, can't seem to get this from TypeScript itself (not sure if just skill issue? :D)
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1790
// it should be there per https://github.com/mdn/browser-compat-data/pull/21875
// https://github.com/ProjectEvergreen/wcc/issues/236
// per the spec, this should only apply to <button> and <input> elements.
popovertarget?: string;
popovertargetaction?: 'show' | 'hide' | 'toggle';
popovertargetaction?: PopoverTargetAction;
};

// map each HTML tag to its attributes
type IntrinsicElementsFromDom = {
[E in keyof HTMLElementTagNameMap]: ElementAttributes<HTMLElementTagNameMap[E]>;
[E in keyof HTMLElementTagNameMap]: ElementAttributes<HTMLElementTagNameMap[E]> &
(E extends 'button' | 'input' ? PopoverTargetAttributes : {});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, that makes sense! nice, thank you, this looks pretty clean 💯

};

declare namespace JSX {
Expand Down
11 changes: 8 additions & 3 deletions test/cases/tsx/src/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
export default class Header extends HTMLElement {
render() {
return (
<button popovertarget="mobile-menu" popovertargetaction="hide">
Close
</button>
<header>
<button popovertarget="mobile-menu" popovertargetaction="hide">
Close
</button>

{/* @ts-expect-error popovertarget should only be valid on <button> and <input> */}
Copy link
Copy Markdown
Member

@thescientist13 thescientist13 Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thank you for adding this as a "test" case. Love that TS will error when your @ts-expect-errors are no longer applicable, so this will definitely help catch us if we regress on this in any way.

<span popovertarget="mobile-menu">Close</span>
</header>
);
}
}