Skip to content

Commit

Permalink
fix: should allow optional properties for images option (vercel#28709)
Browse files Browse the repository at this point in the history
## Bug
- Fixes vercel#28708

- [x] Related issues linked using `fixes #number`
  • Loading branch information
catnose99 committed Sep 8, 2021
1 parent 8921d91 commit 1389339
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions packages/next/client/image.tsx
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Head from '../shared/lib/head'
import { toBase64 } from '../shared/lib/to-base-64'
import {
ImageConfig,
ImageConfigComplete,
imageConfigDefault,
LoaderValue,
VALID_LOADERS,
Expand Down Expand Up @@ -110,7 +110,8 @@ const {
loader: configLoader,
path: configPath,
domains: configDomains,
} = (process.env.__NEXT_IMAGE_OPTS as any as ImageConfig) || imageConfigDefault
} = (process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete) ||
imageConfigDefault
// sort smallest to largest
const allSizes = [...configDeviceSizes, ...configImageSizes]
configDeviceSizes.sort((a, b) => a - b)
Expand Down
12 changes: 7 additions & 5 deletions packages/next/server/config-shared.ts
@@ -1,13 +1,15 @@
import os from 'os'
import { Header, Redirect, Rewrite } from '../lib/load-custom-routes'
import { ImageConfig, imageConfigDefault } from './image-config'
import {
ImageConfig,
ImageConfigComplete,
imageConfigDefault,
} from './image-config'

type NoOptionals<T> = {
[P in keyof T]-?: T[P]
export type NextConfigComplete = Required<NextConfig> & {
images: ImageConfigComplete
}

export type NextConfigComplete = NoOptionals<NextConfig>

export interface I18NConfig {
defaultLocale: string
domains?: DomainLocale[]
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/config.ts
Expand Up @@ -181,7 +181,7 @@ function assignDefaults(userConfig: { [key: string]: any }) {
}

if (result?.images) {
const images: Partial<ImageConfig> = result.images
const images: ImageConfig = result.images

if (typeof images !== 'object') {
throw new Error(
Expand Down
6 changes: 4 additions & 2 deletions packages/next/server/image-config.ts
Expand Up @@ -8,7 +8,7 @@ export const VALID_LOADERS = [

export type LoaderValue = typeof VALID_LOADERS[number]

export type ImageConfig = {
export type ImageConfigComplete = {
deviceSizes: number[]
imageSizes: number[]
loader: LoaderValue
Expand All @@ -18,7 +18,9 @@ export type ImageConfig = {
minimumCacheTTL?: number
}

export const imageConfigDefault: ImageConfig = {
export type ImageConfig = Partial<ImageConfigComplete>

export const imageConfigDefault: ImageConfigComplete = {
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
path: '/_next/image',
Expand Down

0 comments on commit 1389339

Please sign in to comment.