Skip to content

Cannot edit the config after calling defineConfig anymore #2524

@ST-DDT

Description

@ST-DDT

Describe the bug

After the update from 1.0.0-beta.1 to 1.0.0-beta.2 I get a type error when trying to alter the config:

Reproduction

const config = defineConfig({ ... });

if (versionBannerInfix) {
  config.head?.push([
    'script',
    { id: 'restore-banner-preference' },
    `someScript()`,
  ]);
}

export default config;

Working reproduction: https://github.com/faker-js/faker/blob/a6f5a39fff65d8923aab6db8a05a3ab79d097896/docs/.vitepress/config.ts#L257-L272

Expected behavior

I expect it to still work.

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz
    Memory: 52.73 GB / 63.69 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.16.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1848.0), Chromium (114.0.1823.51)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vitepress: 1.0.0-beta.2 => 1.0.0-beta.2

Additional context

Found here: faker-js/faker#2216

// Vitepress Types
type UserConfigExport<ThemeConfig> = UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>> | UserConfigFn<ThemeConfig>;

declare function defineConfig(config: UserConfigExport<DefaultTheme.Config>): UserConfigExport<DefaultTheme.Config>;

The first UserConfigExport variant is a somewhat special case as it is the only that makes sense to change afterwards.

Fix:

Export two signatures:

declare function defineConfig(config: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config>;
declare function defineConfig(config: UserConfigExport<DefaultTheme.Config>): UserConfigExport<DefaultTheme.Config>;

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    typesRelated to typings only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions