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

Implement metadata types support for exactOptionalPropertyTypes #72936

Merged
merged 7 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
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
26 changes: 16 additions & 10 deletions packages/next/src/lib/metadata/types/alternative-urls-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
104 changes: 54 additions & 50 deletions packages/next/src/lib/metadata/types/extra-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,103 +3,107 @@
// 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
// https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
// 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
Expand All @@ -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
}
Loading
Loading