Skip to content

Commit f16e347

Browse files
committed
Add more JSX intrinsic element types
Adds JSX intrinsic element types for React 19, Preact and SolidJS. This enables using the web component in JSX in projects with TypeScript using these libraries, without having to manually augment the corresponding module. Only JSX augmentations are added because other libraries (like Svelte) support custom elements out of the box with TypeScript.
1 parent ef7c955 commit f16e347

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default tseslint.config(
2525
this: { before: false },
2626
},
2727
}],
28+
'@typescript-eslint/no-empty-object-type': 'off',
29+
'@typescript-eslint/no-explicit-any': 'off',
2830
'@typescript-eslint/no-namespace': ['error', {
2931
allowDeclarations: true,
3032
}],

src/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
import { ScrollShadowElement } from './ScrollShadowElement.js'
2-
3-
type IntrinsicBase = JSX.IntrinsicElements extends { span: infer SpanElement }
4-
? SpanElement
5-
: Record<string, unknown>
2+
import './jsx-augmentations.d.ts'
63

74
declare global {
85
interface HTMLElementTagNameMap {
96
'scroll-shadow': ScrollShadowElement
107
}
11-
12-
namespace JSX {
13-
interface IntrinsicElements {
14-
'scroll-shadow': IntrinsicBase & { class?: string }
15-
}
16-
}
178
}
189

19-
export { ScrollShadowElement }
20-
2110
if ('customElements' in window && 'ResizeObserver' in window) {
2211
customElements.define('scroll-shadow', ScrollShadowElement)
2312
}
13+
14+
export { ScrollShadowElement }

src/jsx-augmentations.d.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
type Augmentation<T extends Record<string, any>, ExtraProps = {}> = {
2+
'scroll-shadow': T['span'] & ExtraProps
3+
}
4+
5+
declare global {
6+
// React < 19
7+
namespace JSX {
8+
interface IntrinsicElements extends Augmentation<IntrinsicElements, { class?: string }> {}
9+
}
10+
}
11+
12+
declare module 'react' {
13+
namespace JSX {
14+
interface IntrinsicElements extends Augmentation<IntrinsicElements> {}
15+
}
16+
}
17+
18+
declare module 'react/jsx-runtime' {
19+
namespace JSX {
20+
interface IntrinsicElements extends Augmentation<IntrinsicElements> {}
21+
}
22+
}
23+
24+
declare module 'preact' {
25+
namespace JSX {
26+
interface IntrinsicElements extends Augmentation<IntrinsicElements> {}
27+
}
28+
}
29+
30+
declare module 'preact/jsx-runtime' {
31+
namespace JSX {
32+
interface IntrinsicElements extends Augmentation<IntrinsicElements> {}
33+
}
34+
}
35+
36+
declare module 'solid-js' {
37+
namespace JSX {
38+
interface IntrinsicElements extends Augmentation<IntrinsicElements> {}
39+
}
40+
}
41+
42+
export {}

0 commit comments

Comments
 (0)