-
Notifications
You must be signed in to change notification settings - Fork 77
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
Allow partial configs in environment overrides #1026
Conversation
Fix the TypeScript types so that you don't have to do a full set of config keys in environment overrides
@@ -118,7 +118,7 @@ createCommand.action = async function run(appname, options, command) { | |||
|
|||
const pluginGasket = makeGasket({ | |||
...context.presetConfig, | |||
plugins: context.presets.concat(context.presetConfig.plugins) | |||
plugins: context.presetConfig.plugins.concat(context.presets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an annoying limitation of TypeScript. Because context.presets
is of type Array<Plugin>
it cannot concatenate in Array<Plugin | { default: Plugin }>
because concat
is defined such where the return value is supposed to be the same as the original array. However, it can do this in the reverse order. I assume that the order of plugins doesn't matter.
@@ -38,7 +38,7 @@ export class Gasket { | |||
// prune nullish and/or empty plugins | |||
config.plugins = config.plugins | |||
.filter(Boolean) | |||
.map(plugin => plugin.default || plugin) // quality of life for cjs apps | |||
.map(plugin => 'default' in plugin ? plugin.default : plugin) // quality of life for cjs apps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript is able to use an in
check to narrow a type; seeing if a default
property is falsy doesn't do the same, so the old expression wasn't able to be resolved as a Plugin
object.
Summary
Fix the TypeScript types so that you don't have to do a full set of config keys in environment overrides to avoid TypeScript errors.
Changelog
Test Plan
Added type test