Skip to content

Conversation

@rschristian
Copy link
Member

@rschristian rschristian commented Aug 5, 2025

Closes #2706

This PR cuts down the JSX namespace to only include the actual JSX interfaces, i.e., Element, IntrinsicElements, IntrinsicAttributes, etc. We've been using it to hold most of our DOM-ish typings forever which is a) surprising for users looking for these types, if they can find them at all and b) probably not ideal given the magic handling of JSX by TS. Best to keep it pretty minimal and only load it up with the interfaces expected of it.

This will let users import types directly from Preact, like so:

// Before
import { JSX } from 'preact';

let MyButtonProps: JSX.ButtonHTMLAttributes & {
  //...
}

// After
import { ButtonHTMLAttributes } from 'preact';

let MyButtonProps: ButtonHTMLAttributes & {
  //...
}

Moving these out to a separate declaration file seemed easiest, as we need to re-export all of these types except for the JSXInternal namespace and I found that to be quite fiddly; I frequently broke IntrinsicElements when working on that and so just moved the unrelated types out. Seems less error-prone like this, and does somewhat nicely isolate the JSX-specific types. Might be easier to maintain.

Big ol' breaking change of course, but for the better I think. Should be pretty quick for consumers to fix up.

@coveralls
Copy link

coveralls commented Aug 5, 2025

Coverage Status

coverage: 99.539%. remained the same
when pulling 0fadcae on refactor/jsx-namespace
into 9a54be8 on main.

@rschristian rschristian force-pushed the refactor/jsx-namespace branch from 94c5bc9 to 832c60d Compare August 5, 2025 23:56
Comment on lines -287 to +289
interface ContainerNode {
export interface ContainerNode {
Copy link
Member Author

Choose a reason for hiding this comment

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

Fairly odd: we reference this in /compat/index.d.ts, and that's always been fine, but now it's throwing an error, stating ContainerNode cannot be found. This seems pretty legit to me, seeing as how we weren't exporting it.

@@ -1,4 +1,4 @@
import { createElement, Component, createContext } from '../../';
import { createElement, Component, createContext, HTMLAttributes, MouseEventHandler } from '../../';
Copy link
Member Author

Choose a reason for hiding this comment

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

MouseEventHandler, like ContainerNode above, seems to be a weird instance of global type access that shouldn't exist. I don't know why that worked, or what has since broke it, but I'd say this is correct?

@rschristian rschristian force-pushed the refactor/jsx-namespace branch from 832c60d to 15bf573 Compare August 6, 2025 00:00
src/jsx.d.ts Outdated
Comment on lines 9 to 12
SVGAttributes,
HTMLAttributes,
AnnotationMathMLAttributes,
AnnotationXmlMathMLAttributes,
Copy link
Member Author

@rschristian rschristian Aug 6, 2025

Choose a reason for hiding this comment

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

This mega import statement is kinda gross but I'm not sure an import * as domTypes is all that much better?

@rschristian rschristian marked this pull request as ready for review August 6, 2025 00:04
@preactjs preactjs deleted a comment from github-actions bot Aug 6, 2025
@rschristian rschristian force-pushed the refactor/jsx-namespace branch 2 times, most recently from 15bf573 to 4514c7c Compare August 6, 2025 05:34
@preactjs preactjs deleted a comment from github-actions bot Aug 6, 2025
@rschristian rschristian force-pushed the refactor/jsx-namespace branch from 205c6b0 to 7f478c4 Compare August 8, 2025 18:19
@rschristian rschristian merged commit aeb59e0 into main Aug 8, 2025
5 checks passed
@rschristian rschristian deleted the refactor/jsx-namespace branch August 8, 2025 18:43
@JoviDeCroock JoviDeCroock mentioned this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove irrelevant types from JSX namespace

4 participants