-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: merge config doesn't work when user configs as a function. #12977
Conversation
Run & review this pull request in StackBlitz Codeflow. |
The types already forbid passing a function as an argument, so I don't think we need this? |
Hi, thank u for your response. The reason I made this change was because I was having some issues. I try to split When the I try to look at the source code of defineConfig and mergeConfig, I think the problem is in mergeConfig, because defineConfig can accept an object and a function, and export it directly. After I made this modification, it seemed to fix the issue. Is there a better solution for this?😭 |
You can call the function before passing it to |
OK, thank u for your advices, much appreciate. 👍 |
Not really. export function mergeConfig(
defaults: Record<string, any>,
overrides: Record<string, any>,
isRoot = true,
): Record<string, any> {
return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.')
} But from TS point of view function is assignable to So code below is valid but not working mergeConfig(
defineConfig(() => ({})),
{},
); I'm agreed that it is better to avoid calling functions automatically because in that case we can have unobvious behaviour with initialization order. But we need to forbid passing functions in |
That's a strange TS behaviour, I'm not sure how we can forbid passing functions strictly though, the |
@bluwy export function mergeConfig<T>(
defaults: Record<string, unknown>,
overrides: Record<string, unknown>,
isRoot = true,
): Record<string, unknown> {
return {};
}
mergeConfig(
{base: './', root: 'src', build: {outDir: 'dist'}},
// ❌ Argument of type '() => {}' is not assignable to parameter of type 'Record<string, unknown>'.
() => ({}),
); |
Interesting. I think we'd still need the return type to be |
Description
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).