Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsx): improve meta-tag types with well known values #3276

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions src/jsx/intrinsic-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,68 @@ export namespace JSX {
src?: string | undefined
}

/**
* String literal types with auto-completion
* @see https://github.com/Microsoft/TypeScript/issues/29729
*/
type LiteralUnion<T> = T | (string & Record<never, never>)
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv
*/
type MetaHttpEquiv =
| 'content-security-policy'
| 'content-type'
| 'default-style'
| 'x-ua-compatible'
| 'refresh'
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name
*/
type MetaName =
| 'application-name'
| 'author'
| 'description'
| 'generator'
| 'keywords'
| 'referrer'
| 'theme-color'
| 'color-scheme'
| 'viewport'
| 'creator'
| 'googlebot'
| 'publisher'
| 'robots'
/**
* @see https://ogp.me/
*/
type MetaProperty =
| 'og:title'
| 'og:type'
| 'og:image'
| 'og:url'
| 'og:audio'
| 'og:description'
| 'og:determiner'
| 'og:locale'
| 'og:locale:alternate'
| 'og:site_name'
| 'og:video'
| 'og:image:url'
| 'og:image:secure_url'
| 'og:image:type'
| 'og:image:width'
| 'og:image:height'
| 'og:image:alt'
interface MetaHTMLAttributes extends HTMLAttributes {
charset?: string | undefined
'http-equiv'?: string | undefined
name?: string | undefined
charset?: LiteralUnion<'utf-8'> | undefined
'http-equiv'?: LiteralUnion<MetaHttpEquiv> | undefined
name?: LiteralUnion<MetaName> | undefined
media?: string | undefined
content?: string | undefined
property?: LiteralUnion<MetaProperty> | undefined

// React 19 compatibility
httpEquiv?: string | undefined
httpEquiv?: LiteralUnion<MetaHttpEquiv> | undefined
}

interface MeterHTMLAttributes extends HTMLAttributes {
Expand Down