Skip to content

Commit 86f541b

Browse files
fix: fix children and props type issue in VanJSX
1 parent 701bebd commit 86f541b

File tree

1 file changed

+16
-185
lines changed

1 file changed

+16
-185
lines changed

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

Lines changed: 16 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { FunctionChild } from "./type";
55
type OriginalElement = HTMLElement;
66

77
export declare namespace JSX {
8-
type HTMLAttributes<T> = Partial<Omit<T, "style" | "children">> & {
9-
style?: CSS.Properties;
10-
ref?: State<T>;
11-
children?: ChildDom;
8+
type JSXProp<T, K extends keyof T> = K extends "children"
9+
? ChildDom
10+
: K extends "style"
11+
? CSS.Properties
12+
: K extends "ref"
13+
? State<T>
14+
: T[K] | (() => T[K]) | State<T[K]>;
15+
type HTMLAttributes<T> = {
16+
[K in keyof T]?: JSXProp<T, K>;
1217
};
13-
type SVGAttributes<T> = Partial<Omit<T, "style" | "children">> & {
14-
style?: CSS.Properties;
15-
ref?: State<T>;
16-
children?: ChildDom;
18+
type SVGAttributes<T> = {
19+
[K in keyof T]?: JSXProp<T, K>;
1720
};
1821
export type ElementType = string | FunctionChild<any>;
1922
export interface Element extends OriginalElement {}
@@ -24,181 +27,9 @@ export declare namespace JSX {
2427
children: {};
2528
}
2629
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-
}
30+
export type IntrinsicElements = {
31+
[K in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[K] extends HTMLElement
32+
? HTMLAttributes<HTMLElementTagNameMap[K]>
33+
: SVGAttributes<HTMLElementTagNameMap[K]>;
34+
};
20435
}

0 commit comments

Comments
 (0)