vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.01k stars 1.16k forks source link

Not all constituents of type  UserConfigExport  are callable #6659

Closed pereriksson closed 3 weeks ago

pereriksson commented 3 weeks ago

Prerequisites

"vitest": "^2.1.2"

Describe the bug

When configuring the vitest framework, and the vite config is defined using a function like so:

import { defineConfig, mergeConfig } from 'vitest/config';
import viteConfig from './vite.config';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig(env => mergeConfig(
    viteConfig(env),
    {
      test: {
        ...
      },
      plugins: ...,
    },
  )
);

everything works, but typescript complains about viteConfig(env) that:

TS2349: This expression is not callable.
Not all constituents of type  UserConfigExport  are callable.
Type  UserConfig  has no call signatures.

Reproduction

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1
    Memory: 86.27 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.1.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.3 - /usr/local/bin/npm
    pnpm: 8.6.6 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 129.0.6668.90
    Edge: 129.0.2792.79
    Safari: 17.5

Used Package Manager

npm

Validations

github-actions[bot] commented 3 weeks ago

Hello @pereriksson. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

pereriksson commented 3 weeks ago

@AriPerkkio done!

sheremet-va commented 3 weeks ago

This is an issue with Vite's defineConfig override. It doesn't provide an overload for an async function:

declare function defineConfig(config: UserConfig): UserConfig;
declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
+ declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
declare function defineConfig(config: UserConfigExport): UserConfigExport;

I'd suggest opening an issue in Vite repo. You can see that your code works if a callback is sync:

export default defineConfig(() => {})
pereriksson commented 3 weeks ago

@sheremet-va thanks a lot