Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When scaffolding new app, TypeScript Error in vitest.config.ts #313

Closed
dustindowns opened this issue Jul 10, 2023 · 1 comment
Closed

When scaffolding new app, TypeScript Error in vitest.config.ts #313

dustindowns opened this issue Jul 10, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@dustindowns
Copy link

dustindowns commented Jul 10, 2023

When scaffolding a new app with TypeScript and Vitest using npm init vue@latest, there's a TypeScript error in vitest.config.ts related with the usage of mergeConfig.

Argument of type 'UserConfigExport' is not assignable to parameter of type 'UserConfig | Promise'.
Type 'UserConfigFn' is not assignable to type 'UserConfig | Promise'.ts(2345)

It seems the actual types in use for the "mergeConfig" arguments are UserConfigExport, but "mergeConfig" is expecting them to be of type UserConfig.

Here are the prompt selections:
Screenshot 2023-07-10 at 9 30 50 AM

After installing dependencies, the following error shows up in vitest.config.ts:
Screenshot 2023-07-10 at 9 27 30 AM

@haoqunjiang haoqunjiang added the bug Something isn't working label Jul 11, 2023
haoqunjiang added a commit to haoqunjiang/vite that referenced this issue Jul 11, 2023
Fixes compatibility with `mergeConfig`, as reported in vuejs/create-vue#313

Before the change, `defineConfig` would return `UserConfigExport`, which
is a union type. This would cause `mergeConfig` to fail, as it doesn't
accept the `UserConfigFn` type in the union. (vitejs#13135)

After the change, `defineConfig` returns the same type that it receives,
so it would exclude `UserConfigFn` from the return type whenever
possible.
haoqunjiang added a commit to haoqunjiang/vitest that referenced this issue Jul 24, 2023
Ported from vitejs/vite#13792

Fully fixes issues like vuejs/create-vue#317
and vuejs/create-vue#313

For an easy reproduction, please refer to https://github.com/sodatea/viteste-define-config-bug-repro

I didn't include a test in this PR because:

1. The reproduction is a bit complicated, it only fails on the very
latest Vite versions, but updating Vite would mess up the lockfile.
2. By not updating the dependencies, we can make sure that this fix is
compatible with older versions of Vite, too.
@haoqunjiang
Copy link
Member

Workaround:

  1. Update Vite to the latest version
  2. Then apply this patch: b948832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants