Unverified Commit f3b06b93 authored by Boaris's avatar Boaris Committed by GitHub

Implement metadata types support for `exactOptionalPropertyTypes` (#72936)

parent 28a25af1
......@@ -427,23 +427,29 @@ type UnmatchedLang = 'x-default'
type HrefLang = LangCode | UnmatchedLang
export type Languages<T> = {
[s in HrefLang]?: T
[s in HrefLang]?: T | undefined
}
export type AlternateLinkDescriptor = {
title?: string
title?: string | undefined
url: string | URL
}
export type AlternateURLs = {
canonical?: null | string | URL | AlternateLinkDescriptor
languages?: Languages<null | string | URL | AlternateLinkDescriptor[]>
media?: {
[media: string]: null | string | URL | AlternateLinkDescriptor[]
}
types?: {
[types: string]: null | string | URL | AlternateLinkDescriptor[]
}
canonical?: null | string | URL | AlternateLinkDescriptor | undefined
languages?:
| Languages<null | string | URL | AlternateLinkDescriptor[]>
| undefined
media?:
| {
[media: string]: null | string | URL | AlternateLinkDescriptor[]
}
| undefined
types?:
| {
[types: string]: null | string | URL | AlternateLinkDescriptor[]
}
| undefined
}
export type ResolvedAlternateURLs = {
......
......@@ -3,65 +3,69 @@
// ref: https://developers.facebook.com/docs/applinks/metadata-reference
export type AppLinks = {
ios?: AppLinksApple | Array<AppLinksApple>
iphone?: AppLinksApple | Array<AppLinksApple>
ipad?: AppLinksApple | Array<AppLinksApple>
android?: AppLinksAndroid | Array<AppLinksAndroid>
windows_phone?: AppLinksWindows | Array<AppLinksWindows>
windows?: AppLinksWindows | Array<AppLinksWindows>
windows_universal?: AppLinksWindows | Array<AppLinksWindows>
web?: AppLinksWeb | Array<AppLinksWeb>
ios?: AppLinksApple | Array<AppLinksApple> | undefined
iphone?: AppLinksApple | Array<AppLinksApple> | undefined
ipad?: AppLinksApple | Array<AppLinksApple> | undefined
android?: AppLinksAndroid | Array<AppLinksAndroid> | undefined
windows_phone?: AppLinksWindows | Array<AppLinksWindows> | undefined
windows?: AppLinksWindows | Array<AppLinksWindows> | undefined
windows_universal?: AppLinksWindows | Array<AppLinksWindows> | undefined
web?: AppLinksWeb | Array<AppLinksWeb> | undefined
}
export type ResolvedAppLinks = {
ios?: Array<AppLinksApple>
iphone?: Array<AppLinksApple>
ipad?: Array<AppLinksApple>
android?: Array<AppLinksAndroid>
windows_phone?: Array<AppLinksWindows>
windows?: Array<AppLinksWindows>
windows_universal?: Array<AppLinksWindows>
web?: Array<AppLinksWeb>
ios?: Array<AppLinksApple> | undefined
iphone?: Array<AppLinksApple> | undefined
ipad?: Array<AppLinksApple> | undefined
android?: Array<AppLinksAndroid> | undefined
windows_phone?: Array<AppLinksWindows> | undefined
windows?: Array<AppLinksWindows> | undefined
windows_universal?: Array<AppLinksWindows> | undefined
web?: Array<AppLinksWeb> | undefined
}
export type AppLinksApple = {
url: string | URL
app_store_id?: string | number
app_name?: string
app_store_id?: string | number | undefined
app_name?: string | undefined
}
export type AppLinksAndroid = {
package: string
url?: string | URL
class?: string
app_name?: string
url?: string | URL | undefined
class?: string | undefined
app_name?: string | undefined
}
export type AppLinksWindows = {
url: string | URL
app_id?: string
app_name?: string
app_id?: string | undefined
app_name?: string | undefined
}
export type AppLinksWeb = {
url: string | URL
should_fallback?: boolean
should_fallback?: boolean | undefined
}
// Apple Itunes APp
// https://developer.apple.com/documentation/webkit/promoting_apps_with_smart_app_banners
export type ItunesApp = {
appId: string
appArgument?: string
appArgument?: string | undefined
}
// Viewport meta structure
// https://developer.mozilla.org/docs/Web/HTML/Viewport_meta_tag
// intentionally leaving out user-scalable, use a string if you want that behavior
export type ViewportLayout = {
width?: string | number
height?: string | number
initialScale?: number
minimumScale?: number
maximumScale?: number
userScalable?: boolean
viewportFit?: 'auto' | 'cover' | 'contain'
interactiveWidget?: 'resizes-visual' | 'resizes-content' | 'overlays-content'
width?: string | number | undefined
height?: string | number | undefined
initialScale?: number | undefined
minimumScale?: number | undefined
maximumScale?: number | undefined
userScalable?: boolean | undefined
viewportFit?: 'auto' | 'cover' | 'contain' | undefined
interactiveWidget?:
| 'resizes-visual'
| 'resizes-content'
| 'overlays-content'
| undefined
}
// Apple Web App
......@@ -69,37 +73,37 @@ export type ViewportLayout = {
// https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
export type AppleWebApp = {
// default true
capable?: boolean
title?: string
startupImage?: AppleImage | Array<AppleImage>
capable?: boolean | undefined
title?: string | undefined
startupImage?: AppleImage | Array<AppleImage> | undefined
// default "default"
statusBarStyle?: 'default' | 'black' | 'black-translucent'
statusBarStyle?: 'default' | 'black' | 'black-translucent' | undefined
}
export type AppleImage = string | AppleImageDescriptor
export type AppleImageDescriptor = {
url: string
media?: string
media?: string | undefined
}
export type ResolvedAppleWebApp = {
capable: boolean
title?: string | null
startupImage?: AppleImageDescriptor[] | null
statusBarStyle?: 'default' | 'black' | 'black-translucent'
title?: string | null | undefined
startupImage?: AppleImageDescriptor[] | null | undefined
statusBarStyle?: 'default' | 'black' | 'black-translucent' | undefined
}
export type Facebook = FacebookAppId | FacebookAdmins
export type FacebookAppId = {
appId: string
admins?: never
admins?: never | undefined
}
export type FacebookAdmins = {
appId?: never
appId?: never | undefined
admins: string | string[]
}
export type ResolvedFacebook = {
appId?: string
admins?: string[]
appId?: string | undefined
admins?: string[] | undefined
}
// Format Detection
......@@ -110,9 +114,9 @@ export type ResolvedFacebook = {
// that can initiate a phone call
// https://www.goodemailcode.com/email-code/template.html
export type FormatDetection = {
telephone?: boolean
date?: boolean
address?: boolean
email?: boolean
url?: boolean
telephone?: boolean | undefined
date?: boolean | undefined
address?: boolean | undefined
email?: boolean | undefined
url?: boolean | undefined
}
......@@ -11,37 +11,43 @@ type File = {
type Icon = {
src: string
type?: string
sizes?: string
purpose?: 'any' | 'maskable' | 'monochrome'
type?: string | undefined
sizes?: string | undefined
purpose?: 'any' | 'maskable' | 'monochrome' | undefined
}
export type Manifest = {
background_color?: string
categories?: string[]
description?: string
dir?: 'ltr' | 'rtl' | 'auto'
display?: 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser'
display_override?: (
| 'fullscreen'
| 'standalone'
| 'minimal-ui'
| 'browser'
| 'window-controls-overlay'
)[]
file_handlers?: {
action: string
accept: {
[mimeType: string]: string[]
}
}[]
icons?: Icon[]
id?: string
lang?: string
launch_handler?: {
client_mode: ClientModeEnum | ClientModeEnum[]
}
name?: string
background_color?: string | undefined
categories?: string[] | undefined
description?: string | undefined
dir?: 'ltr' | 'rtl' | 'auto' | undefined
display?: 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser' | undefined
display_override?:
| (
| 'fullscreen'
| 'standalone'
| 'minimal-ui'
| 'browser'
| 'window-controls-overlay'
)[]
| undefined
file_handlers?:
| {
action: string
accept: {
[mimeType: string]: string[]
}
}[]
| undefined
icons?: Icon[] | undefined
id?: string | undefined
lang?: string | undefined
launch_handler?:
| {
client_mode: ClientModeEnum | ClientModeEnum[]
}
| undefined
name?: string | undefined
orientation?:
| 'any'
| 'natural'
......@@ -51,57 +57,72 @@ export type Manifest = {
| 'portrait-secondary'
| 'landscape-primary'
| 'landscape-secondary'
prefer_related_applications?: boolean
protocol_handlers?: {
protocol: string
url: string
}[]
related_applications?: {
platform: string
url: string
id?: string
}[]
scope?: string
screenshots?: {
form_factor?: 'narrow' | 'wide'
label?: string
platform?:
| 'android'
| 'chromeos'
| 'ipados'
| 'ios'
| 'kaios'
| 'macos'
| 'windows'
| 'xbox'
| 'chrome_web_store'
| 'itunes'
| 'microsoft-inbox'
| 'microsoft-store'
| 'play'
src: string
type?: string
sizes?: string
}[]
share_target?: {
action: string
method?: 'get' | 'post' | 'GET' | 'POST'
enctype?: 'application/x-www-form-urlencoded' | 'multipart/form-data'
params: {
title?: string
text?: string
url?: string
files?: File | File[]
}
}
short_name?: string
shortcuts?: {
name: string
short_name?: string
description?: string
url: string
icons?: Icon[]
}[]
start_url?: string
theme_color?: string
| undefined
prefer_related_applications?: boolean | undefined
protocol_handlers?:
| {
protocol: string
url: string
}[]
| undefined
related_applications?:
| {
platform: string
url: string
id?: string | undefined
}[]
| undefined
scope?: string | undefined
screenshots?:
| {
form_factor?: 'narrow' | 'wide' | undefined
label?: string | undefined
platform?:
| 'android'
| 'chromeos'
| 'ipados'
| 'ios'
| 'kaios'
| 'macos'
| 'windows'
| 'xbox'
| 'chrome_web_store'
| 'itunes'
| 'microsoft-inbox'
| 'microsoft-store'
| 'play'
| undefined
src: string
type?: string | undefined
sizes?: string | undefined
}[]
| undefined
share_target?:
| {
action: string
method?: 'get' | 'post' | 'GET' | 'POST' | undefined
enctype?:
| 'application/x-www-form-urlencoded'
| 'multipart/form-data'
| undefined
params: {
title?: string | undefined
text?: string | undefined
url?: string | undefined
files?: File | File[] | undefined
}
}
| undefined
short_name?: string | undefined
shortcuts?:
| {
name: string
short_name?: string | undefined
description?: string | undefined
url: string
icons?: Icon[] | undefined
}[]
| undefined
start_url?: string | undefined
theme_color?: string | undefined
}
......@@ -9,14 +9,14 @@ export interface DeprecatedMetadataFields {
* Deprecated options that have a preferred method
* @deprecated Use appWebApp to configure mobile-web-app-capable which provides
*/
'apple-touch-fullscreen'?: never
'apple-touch-fullscreen'?: never | undefined
/**
* Obsolete since iOS 7.
* @see https://web.dev/apple-touch-icon/
* @deprecated use icons.apple or instead
*/
'apple-touch-icon-precomposed'?: never
'apple-touch-icon-precomposed'?: never | undefined
}
export type TemplateString =
......@@ -37,9 +37,9 @@ export type AbsoluteString = {
export type Author = {
// renders as <link rel="author"...
url?: string | URL
url?: string | URL | undefined
// renders as <meta name="author"...
name?: string
name?: string | undefined
}
// does not include "unsafe-URL". to use this users should
......@@ -63,29 +63,29 @@ export type ColorSchemeEnum =
type RobotsInfo = {
// all and none will be inferred from index/follow boolean options
index?: boolean
follow?: boolean
index?: boolean | undefined
follow?: boolean | undefined
/** @deprecated set index to false instead */
noindex?: never
noindex?: never | undefined
/** @deprecated set follow to false instead */
nofollow?: never
noarchive?: boolean
nosnippet?: boolean
noimageindex?: boolean
nocache?: boolean
notranslate?: boolean
indexifembedded?: boolean
nositelinkssearchbox?: boolean
unavailable_after?: string
'max-video-preview'?: number | string
'max-image-preview'?: 'none' | 'standard' | 'large'
'max-snippet'?: number
nofollow?: never | undefined
noarchive?: boolean | undefined
nosnippet?: boolean | undefined
noimageindex?: boolean | undefined
nocache?: boolean | undefined
notranslate?: boolean | undefined
indexifembedded?: boolean | undefined
nositelinkssearchbox?: boolean | undefined
unavailable_after?: string | undefined
'max-video-preview'?: number | string | undefined
'max-image-preview'?: 'none' | 'standard' | 'large' | undefined
'max-snippet'?: number | undefined
}
export type Robots = RobotsInfo & {
// if you want to specify an alternate robots just for google
googleBot?: string | RobotsInfo
googleBot?: string | RobotsInfo | undefined
}
export type ResolvedRobots = {
......@@ -97,63 +97,67 @@ export type IconURL = string | URL
export type Icon = IconURL | IconDescriptor
export type IconDescriptor = {
url: string | URL
type?: string
sizes?: string
color?: string
type?: string | undefined
sizes?: string | undefined
color?: string | undefined
/** defaults to rel="icon" unless superseded by Icons map */
rel?: string
media?: string
rel?: string | undefined
media?: string | undefined
/**
* @see https://developer.mozilla.org/docs/Web/API/HTMLImageElement/fetchPriority
*/
fetchPriority?: 'high' | 'low' | 'auto'
fetchPriority?: 'high' | 'low' | 'auto' | undefined
}
export type Icons = {
/** rel="icon" */
icon?: Icon | Icon[]
icon?: Icon | Icon[] | undefined
/** rel="shortcut icon" */
shortcut?: Icon | Icon[]
shortcut?: Icon | Icon[] | undefined
/**
* @see https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
* rel="apple-touch-icon"
*/
apple?: Icon | Icon[]
apple?: Icon | Icon[] | undefined
/** rel inferred from descriptor, defaults to "icon" */
other?: IconDescriptor | IconDescriptor[]
other?: IconDescriptor | IconDescriptor[] | undefined
}
export type Verification = {
google?: null | string | number | (string | number)[]
yahoo?: null | string | number | (string | number)[]
yandex?: null | string | number | (string | number)[]
me?: null | string | number | (string | number)[]
google?: null | string | number | (string | number)[] | undefined
yahoo?: null | string | number | (string | number)[] | undefined
yandex?: null | string | number | (string | number)[] | undefined
me?: null | string | number | (string | number)[] | undefined
// if you ad-hoc additional verification
other?: {
[name: string]: string | number | (string | number)[]
}
other?:
| {
[name: string]: string | number | (string | number)[]
}
| undefined
}
export type ResolvedVerification = {
google?: null | (string | number)[]
yahoo?: null | (string | number)[]
yandex?: null | (string | number)[]
me?: null | (string | number)[]
other?: {
[name: string]: (string | number)[]
}
google?: null | (string | number)[] | undefined
yahoo?: null | (string | number)[] | undefined
yandex?: null | (string | number)[] | undefined
me?: null | (string | number)[] | undefined
other?:
| {
[name: string]: (string | number)[]
}
| undefined
}
export type ResolvedIcons = {
icon: IconDescriptor[]
apple: IconDescriptor[]
shortcut?: IconDescriptor[]
other?: IconDescriptor[]
shortcut?: IconDescriptor[] | undefined
other?: IconDescriptor[] | undefined
}
export type ThemeColorDescriptor = {
color: string
media?: string
media?: string | undefined
}
export type Restriction = {
......@@ -165,21 +169,23 @@ export type Videos = {
title: string
thumbnail_loc: string
description: string
content_loc?: string
player_loc?: string
duration?: number
expiration_date?: Date | string
rating?: number
view_count?: number
publication_date?: Date | string
family_friendly?: 'yes' | 'no'
restriction?: Restriction
platform?: Restriction
requires_subscription?: 'yes' | 'no'
uploader?: {
info?: string
content?: string
}
live?: 'yes' | 'no'
tag?: string
content_loc?: string | undefined
player_loc?: string | undefined
duration?: number | undefined
expiration_date?: Date | string | undefined
rating?: number | undefined
view_count?: number | undefined
publication_date?: Date | string | undefined
family_friendly?: 'yes' | 'no' | undefined
restriction?: Restriction | undefined
platform?: Restriction | undefined
requires_subscription?: 'yes' | 'no' | undefined
uploader?:
| {
info?: string | undefined
content?: string | undefined
}
| undefined
live?: 'yes' | 'no' | undefined
tag?: string | undefined
}
......@@ -11,13 +11,13 @@ export type Twitter =
type TwitterMetadata = {
// defaults to card="summary"
site?: string // username for account associated to the site itself
siteId?: string // id for account associated to the site itself
creator?: string // username for the account associated to the creator of the content on the site
creatorId?: string // id for the account associated to the creator of the content on the site
description?: string
title?: string | TemplateString
images?: TwitterImage | Array<TwitterImage>
site?: string | undefined // username for account associated to the site itself
siteId?: string | undefined // id for account associated to the site itself
creator?: string | undefined // username for the account associated to the creator of the content on the site
creatorId?: string | undefined // id for the account associated to the creator of the content on the site
description?: string | undefined
title?: string | TemplateString | undefined
images?: TwitterImage | Array<TwitterImage> | undefined
}
type TwitterSummary = TwitterMetadata & {
card: 'summary'
......@@ -35,26 +35,28 @@ type TwitterApp = TwitterMetadata & {
}
export type TwitterAppDescriptor = {
id: {
iphone?: string | number
ipad?: string | number
googleplay?: string
iphone?: string | number | undefined
ipad?: string | number | undefined
googleplay?: string | undefined
}
url?: {
iphone?: string | URL
ipad?: string | URL
googleplay?: string | URL
}
name?: string
url?:
| {
iphone?: string | URL | undefined
ipad?: string | URL | undefined
googleplay?: string | URL | undefined
}
| undefined
name?: string | undefined
}
type TwitterImage = string | TwitterImageDescriptor | URL
type TwitterImageDescriptor = {
url: string | URL
alt?: string
secureUrl?: string | URL
type?: string
width?: string | number
height?: string | number
alt?: string | undefined
secureUrl?: string | URL | undefined
type?: string | undefined
width?: string | number | undefined
height?: string | number | undefined
}
type TwitterPlayerDescriptor = {
playerUrl: string | URL
......@@ -65,11 +67,11 @@ type TwitterPlayerDescriptor = {
type ResolvedTwitterImage = {
url: string | URL
alt?: string
secureUrl?: string | URL
type?: string
width?: string | number
height?: string | number
alt?: string | undefined
secureUrl?: string | URL | undefined
type?: string | undefined
width?: string | number | undefined
height?: string | number | undefined
}
type ResolvedTwitterSummary = {
site: string | null
......@@ -78,7 +80,7 @@ type ResolvedTwitterSummary = {
creatorId: string | null
description: string | null
title: AbsoluteTemplateString
images?: Array<ResolvedTwitterImage>
images?: Array<ResolvedTwitterImage> | undefined
}
type ResolvedTwitterPlayer = ResolvedTwitterSummary & {
players: Array<TwitterPlayerDescriptor>
......
import type { MetadataRoute } from 'next'
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
;() => {
;({
background_color: undefined,
categories: undefined,
description: undefined,
dir: undefined,
display: undefined,
display_override: undefined,
file_handlers: undefined,
icons: undefined,
id: undefined,
lang: undefined,
launch_handler: undefined,
name: undefined,
orientation: undefined,
prefer_related_applications: undefined,
protocol_handlers: undefined,
related_applications: undefined,
scope: undefined,
screenshots: undefined,
share_target: undefined,
short_name: undefined,
shortcuts: undefined,
start_url: undefined,
theme_color: undefined,
}) satisfies MetadataRoute.Manifest
;({
icons: [
{
src: '',
type: undefined,
sizes: undefined,
purpose: undefined,
},
],
related_applications: [
{
platform: '',
url: '',
id: undefined,
},
],
screenshots: [
{
form_factor: undefined,
label: undefined,
platform: undefined,
src: '',
type: undefined,
sizes: undefined,
},
],
share_target: {
action: '',
method: undefined,
enctype: undefined,
params: {
title: undefined,
text: undefined,
url: undefined,
files: undefined,
},
},
shortcuts: [
{
name: '',
short_name: undefined,
description: undefined,
url: '',
icons: undefined,
},
],
}) satisfies MetadataRoute.Manifest
}
import type { MetadataRoute } from 'next'
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
;() => {
;({
rules: {
userAgent: undefined,
allow: undefined,
disallow: undefined,
crawlDelay: undefined,
},
sitemap: undefined,
host: undefined,
}) satisfies MetadataRoute.Robots
}
import type { MetadataRoute } from 'next'
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
;() => {
;({
url: '',
lastModified: undefined,
changeFrequency: undefined,
priority: undefined,
alternates: undefined,
images: undefined,
videos: undefined,
}) satisfies MetadataRoute.Sitemap[number]
;({
url: '',
alternates: {
languages: undefined,
},
videos: [
{
title: '',
thumbnail_loc: '',
description: '',
content_loc: undefined,
player_loc: undefined,
duration: undefined,
expiration_date: undefined,
rating: undefined,
view_count: undefined,
publication_date: undefined,
family_friendly: undefined,
restriction: undefined,
platform: undefined,
requires_subscription: undefined,
uploader: undefined,
live: undefined,
tag: undefined,
},
],
}) satisfies MetadataRoute.Sitemap[number]
;({
url: '',
alternates: {
languages: {
en: undefined,
},
},
videos: [
{
title: '',
thumbnail_loc: '',
description: '',
uploader: {
info: undefined,
content: undefined,
},
},
],
}) satisfies MetadataRoute.Sitemap[number]
}
import type { Viewport } from 'next'
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
;() => {
;({
width: undefined,
height: undefined,
initialScale: undefined,
minimumScale: undefined,
maximumScale: undefined,
userScalable: undefined,
viewportFit: undefined,
interactiveWidget: undefined,
themeColor: undefined,
colorScheme: undefined,
}) satisfies Viewport
;({
themeColor: {
color: '',
media: undefined,
},
}) satisfies Viewport
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment