Skip to content

Commit f26a1aa

Browse files
authored
Merge pull request #166 from yahia-berashish/main
Fix children and props type issue in VanJSX
2 parents 701bebd + 3304ff9 commit f26a1aa

File tree

1 file changed

+14
-187
lines changed

1 file changed

+14
-187
lines changed

addons/van_jsx/src/jsx-internal.d.ts

Lines changed: 14 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import { State, ChildDom } from "vanjs-core";
33
import { FunctionChild } from "./type";
44

55
type OriginalElement = HTMLElement;
6+
type JSXProp<T, K extends keyof T> = T[K] | (() => T[K]) | State<T[K]>;
67

78
export declare namespace JSX {
8-
type HTMLAttributes<T> = Partial<Omit<T, "style" | "children">> & {
9-
style?: CSS.Properties;
10-
ref?: State<T>;
11-
children?: ChildDom;
12-
};
13-
type SVGAttributes<T> = Partial<Omit<T, "style" | "children">> & {
14-
style?: CSS.Properties;
15-
ref?: State<T>;
16-
children?: ChildDom;
17-
};
9+
type HTMLAttributes<T> = {
10+
[K in keyof Omit<T, "children" | "style">]?: JSXProp<T, K>;
11+
} & Partial<{ children: ChildDom; style: CSS.Properties; ref: State<T> }>;
12+
13+
type SVGAttributes<T> = {
14+
[K in keyof Omit<T, "children" | "style">]?: JSXProp<T, K>;
15+
} & Partial<{ children: ChildDom; style: CSS.Properties; ref: State<T> }>;
16+
1817
export type ElementType = string | FunctionChild<any>;
1918
export interface Element extends OriginalElement {}
2019
export interface ElementAttributesProperty {
@@ -24,181 +23,9 @@ export declare namespace JSX {
2423
children: {};
2524
}
2625
export interface IntrinsicAttributes {}
27-
export interface IntrinsicElements {
28-
a: HTMLAttributes<HTMLAnchorElement>;
29-
abbr: HTMLAttributes<HTMLElement>;
30-
address: HTMLAttributes<HTMLElement>;
31-
area: HTMLAttributes<HTMLAreaElement>;
32-
article: HTMLAttributes<HTMLElement>;
33-
aside: HTMLAttributes<HTMLElement>;
34-
audio: HTMLAttributes<HTMLAudioElement>;
35-
b: HTMLAttributes<HTMLElement>;
36-
base: HTMLAttributes<HTMLBaseElement>;
37-
bdi: HTMLAttributes<HTMLElement>;
38-
bdo: HTMLAttributes<HTMLElement>;
39-
big: HTMLAttributes<HTMLElement>;
40-
blockquote: HTMLAttributes<HTMLQuoteElement>;
41-
body: HTMLAttributes<HTMLBodyElement>;
42-
br: HTMLAttributes<HTMLBRElement>;
43-
button: HTMLAttributes<HTMLButtonElement>;
44-
canvas: HTMLAttributes<HTMLCanvasElement>;
45-
caption: HTMLAttributes<HTMLTableCaptionElement>;
46-
cite: HTMLAttributes<HTMLElement>;
47-
code: HTMLAttributes<HTMLElement>;
48-
col: HTMLAttributes<HTMLTableColElement>;
49-
colgroup: HTMLAttributes<HTMLTableColElement>;
50-
data: HTMLAttributes<HTMLDataElement>;
51-
datalist: HTMLAttributes<HTMLDataListElement>;
52-
dd: HTMLAttributes<HTMLElement>;
53-
del: HTMLAttributes<HTMLModElement>;
54-
details: HTMLAttributes<HTMLDetailsElement>;
55-
dfn: HTMLAttributes<HTMLElement>;
56-
dialog: HTMLAttributes<HTMLDialogElement>;
57-
div: HTMLAttributes<HTMLDivElement>;
58-
dl: HTMLAttributes<HTMLDListElement>;
59-
dt: HTMLAttributes<HTMLElement>;
60-
em: HTMLAttributes<HTMLElement>;
61-
embed: HTMLAttributes<HTMLEmbedElement>;
62-
fieldset: HTMLAttributes<HTMLFieldSetElement>;
63-
figcaption: HTMLAttributes<HTMLElement>;
64-
figure: HTMLAttributes<HTMLElement>;
65-
footer: HTMLAttributes<HTMLElement>;
66-
form: HTMLAttributes<HTMLFormElement>;
67-
h1: HTMLAttributes<HTMLHeadingElement>;
68-
h2: HTMLAttributes<HTMLHeadingElement>;
69-
h3: HTMLAttributes<HTMLHeadingElement>;
70-
h4: HTMLAttributes<HTMLHeadingElement>;
71-
h5: HTMLAttributes<HTMLHeadingElement>;
72-
h6: HTMLAttributes<HTMLHeadingElement>;
73-
head: HTMLAttributes<HTMLHeadElement>;
74-
header: HTMLAttributes<HTMLElement>;
75-
hgroup: HTMLAttributes<HTMLElement>;
76-
hr: HTMLAttributes<HTMLHRElement>;
77-
html: HTMLAttributes<HTMLHtmlElement>;
78-
i: HTMLAttributes<HTMLElement>;
79-
iframe: HTMLAttributes<HTMLIFrameElement>;
80-
img: HTMLAttributes<HTMLImageElement>;
81-
input: HTMLAttributes<HTMLInputElement>;
82-
ins: HTMLAttributes<HTMLModElement>;
83-
kbd: HTMLAttributes<HTMLElement>;
84-
keygen: HTMLAttributes<HTMLUnknownElement>;
85-
label: HTMLAttributes<HTMLLabelElement>;
86-
legend: HTMLAttributes<HTMLLegendElement>;
87-
li: HTMLAttributes<HTMLLIElement>;
88-
link: HTMLAttributes<HTMLLinkElement>;
89-
main: HTMLAttributes<HTMLElement>;
90-
map: HTMLAttributes<HTMLMapElement>;
91-
mark: HTMLAttributes<HTMLElement>;
92-
marquee: HTMLAttributes<HTMLMarqueeElement>;
93-
menu: HTMLAttributes<HTMLMenuElement>;
94-
menuitem: HTMLAttributes<HTMLUnknownElement>;
95-
meta: HTMLAttributes<HTMLMetaElement>;
96-
meter: HTMLAttributes<HTMLMeterElement>;
97-
nav: HTMLAttributes<HTMLElement>;
98-
noscript: HTMLAttributes<HTMLElement>;
99-
object: HTMLAttributes<HTMLObjectElement>;
100-
ol: HTMLAttributes<HTMLOListElement>;
101-
optgroup: HTMLAttributes<HTMLOptGroupElement>;
102-
option: HTMLAttributes<HTMLOptionElement>;
103-
output: HTMLAttributes<HTMLOutputElement>;
104-
p: HTMLAttributes<HTMLParagraphElement>;
105-
param: HTMLAttributes<HTMLParamElement>;
106-
picture: HTMLAttributes<HTMLPictureElement>;
107-
pre: HTMLAttributes<HTMLPreElement>;
108-
progress: HTMLAttributes<HTMLProgressElement>;
109-
q: HTMLAttributes<HTMLQuoteElement>;
110-
rp: HTMLAttributes<HTMLElement>;
111-
rt: HTMLAttributes<HTMLElement>;
112-
ruby: HTMLAttributes<HTMLElement>;
113-
s: HTMLAttributes<HTMLElement>;
114-
samp: HTMLAttributes<HTMLElement>;
115-
script: HTMLAttributes<HTMLScriptElement>;
116-
search: HTMLAttributes<HTMLElement>;
117-
section: HTMLAttributes<HTMLElement>;
118-
select: HTMLAttributes<HTMLSelectElement>;
119-
slot: HTMLAttributes<HTMLSlotElement>;
120-
small: HTMLAttributes<HTMLElement>;
121-
source: HTMLAttributes<HTMLSourceElement>;
122-
span: HTMLAttributes<HTMLSpanElement>;
123-
strong: HTMLAttributes<HTMLElement>;
124-
style: HTMLAttributes<HTMLStyleElement>;
125-
sub: HTMLAttributes<HTMLElement>;
126-
summary: HTMLAttributes<HTMLElement>;
127-
sup: HTMLAttributes<HTMLElement>;
128-
table: HTMLAttributes<HTMLTableElement>;
129-
tbody: HTMLAttributes<HTMLTableSectionElement>;
130-
td: HTMLAttributes<HTMLTableCellElement>;
131-
textarea: HTMLAttributes<HTMLTextAreaElement>;
132-
tfoot: HTMLAttributes<HTMLTableSectionElement>;
133-
th: HTMLAttributes<HTMLTableCellElement>;
134-
thead: HTMLAttributes<HTMLTableSectionElement>;
135-
time: HTMLAttributes<HTMLTimeElement>;
136-
title: HTMLAttributes<HTMLTitleElement>;
137-
tr: HTMLAttributes<HTMLTableRowElement>;
138-
track: HTMLAttributes<HTMLTrackElement>;
139-
u: HTMLAttributes<HTMLElement>;
140-
ul: HTMLAttributes<HTMLUListElement>;
141-
var: HTMLAttributes<HTMLElement>;
142-
video: HTMLAttributes<HTMLVideoElement>;
143-
wbr: HTMLAttributes<HTMLElement>;
144-
svg: SVGAttributes<SVGSVGElement>;
145-
animate: SVGAttributes<SVGAnimateElement>;
146-
circle: SVGAttributes<SVGCircleElement>;
147-
animateMotion: SVGAttributes<SVGAnimateMotionElement>;
148-
animateTransform: SVGAttributes<SVGAnimateTransformElement>;
149-
clipPath: SVGAttributes<SVGClipPathElement>;
150-
defs: SVGAttributes<SVGDefsElement>;
151-
desc: SVGAttributes<SVGDescElement>;
152-
ellipse: SVGAttributes<SVGEllipseElement>;
153-
feBlend: SVGAttributes<SVGFEBlendElement>;
154-
feColorMatrix: SVGAttributes<SVGFEColorMatrixElement>;
155-
feComponentTransfer: SVGAttributes<SVGFEComponentTransferElement>;
156-
feComposite: SVGAttributes<SVGFECompositeElement>;
157-
feConvolveMatrix: SVGAttributes<SVGFEConvolveMatrixElement>;
158-
feDiffuseLighting: SVGAttributes<SVGFEDiffuseLightingElement>;
159-
feDisplacementMap: SVGAttributes<SVGFEDisplacementMapElement>;
160-
feDistantLight: SVGAttributes<SVGFEDistantLightElement>;
161-
feDropShadow: SVGAttributes<SVGFEDropShadowElement>;
162-
feFlood: SVGAttributes<SVGFEFloodElement>;
163-
feFuncA: SVGAttributes<SVGFEFuncAElement>;
164-
feFuncB: SVGAttributes<SVGFEFuncBElement>;
165-
feFuncG: SVGAttributes<SVGFEFuncGElement>;
166-
feFuncR: SVGAttributes<SVGFEFuncRElement>;
167-
feGaussianBlur: SVGAttributes<SVGFEGaussianBlurElement>;
168-
feImage: SVGAttributes<SVGFEImageElement>;
169-
feMerge: SVGAttributes<SVGFEMergeElement>;
170-
feMergeNode: SVGAttributes<SVGFEMergeNodeElement>;
171-
feMorphology: SVGAttributes<SVGFEMorphologyElement>;
172-
feOffset: SVGAttributes<SVGFEOffsetElement>;
173-
fePointLight: SVGAttributes<SVGFEPointLightElement>;
174-
feSpecularLighting: SVGAttributes<SVGFESpecularLightingElement>;
175-
feSpotLight: SVGAttributes<SVGFESpotLightElement>;
176-
feTile: SVGAttributes<SVGFETileElement>;
177-
feTurbulence: SVGAttributes<SVGFETurbulenceElement>;
178-
filter: SVGAttributes<SVGFilterElement>;
179-
foreignObject: SVGAttributes<SVGForeignObjectElement>;
180-
g: SVGAttributes<SVGGElement>;
181-
image: SVGAttributes<SVGImageElement>;
182-
line: SVGAttributes<SVGLineElement>;
183-
linearGradient: SVGAttributes<SVGLinearGradientElement>;
184-
marker: SVGAttributes<SVGMarkerElement>;
185-
mask: SVGAttributes<SVGMaskElement>;
186-
metadata: SVGAttributes<SVGMetadataElement>;
187-
mpath: SVGAttributes<SVGMPathElement>;
188-
path: SVGAttributes<SVGPathElement>;
189-
pattern: SVGAttributes<SVGPatternElement>;
190-
polygon: SVGAttributes<SVGPolygonElement>;
191-
polyline: SVGAttributes<SVGPolylineElement>;
192-
radialGradient: SVGAttributes<SVGRadialGradientElement>;
193-
rect: SVGAttributes<SVGRectElement>;
194-
set: SVGAttributes<SVGSetElement>;
195-
stop: SVGAttributes<SVGStopElement>;
196-
switch: SVGAttributes<SVGSwitchElement>;
197-
symbol: SVGAttributes<SVGSymbolElement>;
198-
text: SVGAttributes<SVGTextElement>;
199-
textPath: SVGAttributes<SVGTextPathElement>;
200-
tspan: SVGAttributes<SVGTSpanElement>;
201-
use: SVGAttributes<SVGUseElement>;
202-
view: SVGAttributes<SVGViewElement>;
203-
}
26+
export type IntrinsicElements = {
27+
[K in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[K] extends HTMLElement
28+
? HTMLAttributes<HTMLElementTagNameMap[K]>
29+
: SVGAttributes<HTMLElementTagNameMap[K]>;
30+
};
20431
}

0 commit comments

Comments
 (0)