Skip to content

Commit

Permalink
type improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jul 25, 2024
1 parent ba0a336 commit 860dbcf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions packages/next/src/lib/interop-default.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function interopDefault(mod: any) {
return mod.default || mod
export function interopDefault<T extends {} | { default: any }>(
mod: T
): T extends { default: infer U } ? U : T {
return 'default' in mod ? mod.default : mod
}
9 changes: 5 additions & 4 deletions packages/next/src/lib/metadata/resolve-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,9 @@ async function collectStaticImagesFiles(
if (!metadata?.[type]) return undefined

const iconPromises = metadata[type as 'icon' | 'apple'].map(
async (imageModule: (p: any) => Promise<MetadataImageModule[]>) =>
interopDefault(await imageModule(props))
async (imageModule: (p: any) => Promise<MetadataImageModule[]>) => {
return interopDefault(await imageModule(props))
}
)

return iconPromises?.length > 0
Expand Down Expand Up @@ -579,7 +580,7 @@ function inheritFromMetadata(
const commonOgKeys = ['title', 'description', 'images'] as const
function postProcessMetadata(
metadata: ResolvedMetadata,
favicon: any,
favicon: IconDescriptor | undefined,
titleTemplates: TitleTemplates,
metadataContext: MetadataContext
): ResolvedMetadata {
Expand Down Expand Up @@ -767,7 +768,7 @@ export async function accumulateMetadata(
warnings: new Set<string>(),
}

let favicon
let favicon: IconDescriptor | undefined
for (let i = 0; i < metadataItems.length; i++) {
const staticFilesMetadata = metadataItems[i][1]

Expand Down
12 changes: 8 additions & 4 deletions packages/next/src/lib/metadata/types/icons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { IconDescriptor } from './metadata-types'
import type { TwitterImage } from './twitter-types'
import type { OGImage } from './opengraph-types'

export type StaticMetadata = {
icon: any[] | undefined
apple: any[] | undefined
openGraph: any[] | undefined
twitter: any[] | undefined
icon: IconDescriptor[] | undefined
apple: IconDescriptor[] | undefined
openGraph: OGImage[] | undefined
twitter: TwitterImage[] | undefined
manifest: string | undefined
} | null
2 changes: 1 addition & 1 deletion packages/next/src/lib/metadata/types/opengraph-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type OpenGraphVideoOther = OpenGraphMetadata & {
type: 'video.other'
}

type OGImage = string | OGImageDescriptor | URL
export type OGImage = string | OGImageDescriptor | URL
type OGImageDescriptor = {
url: string | URL
secureUrl?: string | URL
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/metadata/types/twitter-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type TwitterAppDescriptor = {
name?: string
}

type TwitterImage = string | TwitterImageDescriptor | URL
export type TwitterImage = string | TwitterImageDescriptor | URL
type TwitterImageDescriptor = {
url: string | URL
alt?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/turbopack-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function validateTurboNextConfig({
await loadConfig(phase, dir, {
rawConfig: true,
})
) as NextConfig
)

if (typeof rawNextConfig === 'function') {
rawNextConfig = (rawNextConfig as any)(phase, {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/load-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ async function loadComponentsImpl<N = any>({
page: string
isAppPath: boolean
}): Promise<LoadComponentsReturnType<N>> {
let DocumentMod = {}
let AppMod = {}
let DocumentMod: DocumentType = {} as any
let AppMod: AppType = {} as any
if (!isAppPath) {
;[DocumentMod, AppMod] = await Promise.all([
requirePage('/_document', distDir, false),
Expand Down

0 comments on commit 860dbcf

Please sign in to comment.