From 68a13f5061e24f54d340721a560e676ef7afb557 Mon Sep 17 00:00:00 2001 From: CatNose <34590683+catnose99@users.noreply.github.com> Date: Wed, 1 Sep 2021 22:52:50 +0900 Subject: [PATCH 1/3] fix: should allow partial ImageConfig for images option --- packages/next/server/config-shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index d62edf36c62bf..8cb8126fb7da3 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -81,7 +81,7 @@ export type NextConfig = { [key: string]: any } & { pageExtensions?: string[] compress?: boolean poweredByHeader?: boolean - images?: ImageConfig + images?: Partial devIndicators?: { buildActivity?: boolean } From 52e1cca1133758386e6942bd1fc5a2290a54730d Mon Sep 17 00:00:00 2001 From: catnose99 Date: Thu, 2 Sep 2021 10:08:19 +0900 Subject: [PATCH 2/3] fix: type errors for `ImageConfig` --- packages/next/client/image.tsx | 5 +++-- packages/next/server/config-shared.ts | 14 ++++++++------ packages/next/server/config.ts | 2 +- packages/next/server/image-config.ts | 6 ++++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/next/client/image.tsx b/packages/next/client/image.tsx index 5174d5f3f5678..9730f0d5604d3 100644 --- a/packages/next/client/image.tsx +++ b/packages/next/client/image.tsx @@ -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, @@ -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) diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index 8cb8126fb7da3..fc3e6e3949d64 100644 --- a/packages/next/server/config-shared.ts +++ b/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 = { - [P in keyof T]-?: T[P] +export interface NextConfigComplete extends Required { + images: ImageConfigComplete } -export type NextConfigComplete = NoOptionals - export interface I18NConfig { defaultLocale: string domains?: DomainLocale[] @@ -81,7 +83,7 @@ export type NextConfig = { [key: string]: any } & { pageExtensions?: string[] compress?: boolean poweredByHeader?: boolean - images?: Partial + images?: ImageConfig devIndicators?: { buildActivity?: boolean } diff --git a/packages/next/server/config.ts b/packages/next/server/config.ts index 52f10d91ebde9..0c359fc286aec 100644 --- a/packages/next/server/config.ts +++ b/packages/next/server/config.ts @@ -181,7 +181,7 @@ function assignDefaults(userConfig: { [key: string]: any }) { } if (result?.images) { - const images: Partial = result.images + const images: ImageConfig = result.images if (typeof images !== 'object') { throw new Error( diff --git a/packages/next/server/image-config.ts b/packages/next/server/image-config.ts index e978a419c9c8e..9102986588331 100644 --- a/packages/next/server/image-config.ts +++ b/packages/next/server/image-config.ts @@ -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 @@ -18,7 +18,9 @@ export type ImageConfig = { minimumCacheTTL?: number } -export const imageConfigDefault: ImageConfig = { +export type ImageConfig = Partial + +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', From 26356cfa0b43a790f5c23622dda225b250aa1213 Mon Sep 17 00:00:00 2001 From: CatNose <34590683+catnose99@users.noreply.github.com> Date: Sat, 4 Sep 2021 08:42:24 +0900 Subject: [PATCH 3/3] fix: use type alias for NextConfigComplete Co-authored-by: Steven --- packages/next/server/config-shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index fc3e6e3949d64..04dc3fa7c41a5 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -6,7 +6,7 @@ import { imageConfigDefault, } from './image-config' -export interface NextConfigComplete extends Required { +export type NextConfigComplete = Required & { images: ImageConfigComplete }