From 33189b87656eb54b4e30f44f55d1af65d4a0a91f Mon Sep 17 00:00:00 2001 From: TOMIKAWA Sotaro <15074382+ssssota@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:14:31 +0900 Subject: [PATCH] feat(jsx): improve `type` (MIME) attribute types (#3305) * feat(jsx): improve `type` (MIME) attribute types embed, link, object, script, source, and style elements * fix(jsx): `source` element allows only media mime in type attribute --- src/jsx/intrinsic-elements.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/jsx/intrinsic-elements.ts b/src/jsx/intrinsic-elements.ts index cb66f45c..dd15aeb5 100644 --- a/src/jsx/intrinsic-elements.ts +++ b/src/jsx/intrinsic-elements.ts @@ -287,7 +287,7 @@ export namespace JSX { interface EmbedHTMLAttributes extends HTMLAttributes { height?: number | string | undefined src?: string | undefined - type?: string | undefined + type?: StringLiteralUnion | undefined width?: number | string | undefined } @@ -495,7 +495,7 @@ export namespace JSX { imagesizes?: string | undefined referrerpolicy?: HTMLAttributeReferrerPolicy | undefined sizes?: string | undefined - type?: string | undefined + type?: StringLiteralUnion | undefined charSet?: string | undefined // React 19 compatibility @@ -607,7 +607,7 @@ export namespace JSX { form?: string | undefined height?: number | string | undefined name?: string | undefined - type?: string | undefined + type?: StringLiteralUnion | undefined usemap?: string | undefined width?: number | string | undefined } @@ -658,7 +658,10 @@ export namespace JSX { nomodule?: boolean | undefined referrerpolicy?: HTMLAttributeReferrerPolicy | undefined src?: string | undefined - type?: string | undefined + /** + * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type + */ + type?: StringLiteralUnion<'' | 'text/javascript' | 'importmap' | 'module'> | undefined // React 19 compatibility crossOrigin?: CrossOrigin @@ -681,20 +684,24 @@ export namespace JSX { value?: string | ReadonlyArray | number | undefined } + type MediaMime = BaseMime & (`image/${string}` | `audio/${string}` | `video/${string}`) interface SourceHTMLAttributes extends HTMLAttributes { height?: number | string | undefined media?: string | undefined sizes?: string | undefined src?: string | undefined srcset?: string | undefined - type?: string | undefined + type?: StringLiteralUnion | undefined width?: number | string | undefined } interface StyleHTMLAttributes extends HTMLAttributes { media?: string | undefined scoped?: boolean | undefined - type?: string | undefined + /** + * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style#type + */ + type?: '' | 'text/css' | undefined // React 19 compatibility href?: string | undefined