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

refactor: add new overload to the type of defineConfig #13958

Merged

Conversation

vinassefranche
Copy link
Contributor

Description

Fixes #13950 (at least partially)
Using a generic type for defineConfig avoids having the result being typed with a union type, with both functions or objects.

Additional context

I've run the typecheck locally and everything passed.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 26, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vinassefranche vinassefranche changed the title Use type generic to define the type of defineConfig refactor: Use type generic to define the type of defineConfig Jul 26, 2023
@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Jul 26, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ❌ failure
astro ✅ success
histoire ❌ failure
iles ❌ failure
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ✅ success
nx ✅ success
previewjs ✅ success
qwik ❌ failure
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ❌ failure
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

@vinassefranche vinassefranche changed the title refactor: Use type generic to define the type of defineConfig refactor(defineConfig): Use type generic to define the type of defineConfig Jul 26, 2023
@vinassefranche vinassefranche changed the title refactor(defineConfig): Use type generic to define the type of defineConfig refactor: use type generic to define the type of defineConfig Jul 26, 2023
@haoqunjiang
Copy link
Member

haoqunjiang commented Jul 26, 2023

I've tried this approach before.

First, it breaks Qwik's types because of an as any casting in their code https://github.com/BuilderIO/qwik/blob/d886be703d19545b9c56ca136ad9d2d7e349f871/packages/qwik-worker/vite.config.ts#L42
The reason is: microsoft/TypeScript#54987 (comment)

Secondly, extends ends up too permissive. See this example: https://www.typescriptlang.org/play?#code/C4TwDgpgBAqgzhATgYQPYDsBmBLA5lAXigG8AoKKYAQ0VwmAC4oAiCOAVmagB8W2AmAAwBGTjz5x0EAB7BmAbnJQcAGwgA5KgFsITABSZUiLVUZQ4wRNnS4AlIQB85y9dyKAvotCQoaLHgBRdAA3QihUACMAKwgAY2BSUhkwI2BKcGh4JD8cXAAxdAB5aLi0oj0IEKYcwJD7AicslAxcpOkUxDTvTIRm-3z0AAVEVC1sBDCKqt8W2uD6p2HR8YgAHiaa3Ac2jq6M2F7NgsnK4OrZ3CD5xwPsi-ElsYR1w4vtndT0nw2LgPbPghKXg-fpAqCPFYvO79bYUYGvfoFYoxeJgkG5AoQhBohEY9CJAD0ACoieQiVAACr7AAWEBUkEQlFQUBMAGtoNg0hAqHBsEgmVAAK4TYKciAAOliF3FwDgZKgVFisQgYFlCqgABNsIhSiQAAIqays259XLucIleIAGnCjKoykF6Hi2AwlGppigOuAgsQ6DgUE54vlFNpDqdwBd6E9cQg2GCbHVxANRpm-Su5siKK67q5-wQ-uAAHdmWARgyI2wGPKAAZSrQmdAa6tQCqc2mM6sAcgiguwKg1nebRigXd68cHthtVEbI60qA1EGrQagRIJH06YedroXOCkmz0Uv6THReFsx9xeHXaUwjq3UZ31gg+8PuSYWLWJ62Z-BIyeH4vWxXpuEbbhAu5PhcB4XOe0K5H8uzfp+8GpEBN7hpGmpgY+z7QSamzIZ0iEAQRaRkBQXo+lGL6Xu4iRoXemHgZsADqbYAOKVEg2CxHAqwUlAMjAJUGr+kh-ydA4UFHpS378WR0ber6UDUW4pC0aQD57hcrHANSHFSFYPF6HoCwtvJ1C0PQTCsBwzBWkoqgaNougtoYximKZ1bWAu0jigAJMQbkmGUBBEDZXAAPwsFoURwFw1mxLFzDuNW9nuLYtiKKQBIEuY1KoIK-YCYgIyMhEcRUMK0CoJgbrQI6rLoKghZRqWqDliAGlYVp-Q6XpnGGXAejmTQdBmDZnD2RQjmaDo+hBR5NxeY2Mj+YFRjBYQoUSJF0VJVACVJSlU3mKMEAwOgjXNUMZZIKATDCGpmWJF1TGQSNlnjWwk0OX2Tlza5G2LQ0I7eatAULSFYVsLtzAxXFB0sIlcXHU9WU5XlBVFUgpVQOVsSVRMNV1UKl1NS1UBtR1r3Ye9SgWWN1nfXZv1qLNLkGEDwCeWDvkQ1zW3QwjUVw-th0o6lShwGdF1XS1SwdQ9aOkEAA

Copy link
Member

@haoqunjiang haoqunjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding more overloads can solve your original problem already?

@vinassefranche
Copy link
Contributor Author

Maybe adding more overloads can solve your original problem already?

I agree that adding this overload should fix my issue:

export function defineConfig(config: UserConfigFnObject): UserConfigFnObject

I'll check that it's indeed the case and hope it won't break something else

@vinassefranche vinassefranche force-pushed the improve-type-definition-of-defineConfig branch from d965544 to 070f065 Compare July 26, 2023 17:19
@vinassefranche vinassefranche changed the title refactor: use type generic to define the type of defineConfig refactor: add new overload to the type of defineConfig Jul 26, 2023
@vinassefranche
Copy link
Contributor Author

@sodatea I've tested with the new overload and it would indeed fix my use case (if the same change would be done in vitest too but that's another issue and I'll try to port it when this is resolved)
Let's see if everything works fine with only the overload

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Jul 26, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ❌ failure
astro ✅ success
histoire ❌ failure
iles ❌ failure
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ✅ success
nx ✅ success
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ❌ failure
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

@patak-dev
Copy link
Member

Ecosystem CI looks good, same tests are failing in main

@patak-dev patak-dev merged commit 24c12fe into vitejs:main Jul 27, 2023
@vinassefranche vinassefranche deleted the improve-type-definition-of-defineConfig branch July 27, 2023 07:19
haoqunjiang added a commit to haoqunjiang/vitest that referenced this pull request Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type incompatibilities between mergeConfig and defineConfig when the latter is used with a function
3 participants