Unpartial
Unpartial a config
It is very common to define a Config interface and Partial it in a function argument.
When we received the arguement, we want to merge it with our default config before using it:
import { unpartial } from 'unpartial'
interface Config {
require: { a: number }
optional?: { a: number }
}
const defaultConfig = { require: { a: 1 }}
function foo(givenConfig: Partial<Config>) {
const config = unpartial(givenConfig, defaultConfig);
}
It also support merging two default configs.
This is useful when you are extending config from some other package/class.
import { unpartial} from 'unpartial'
import { Option, defaultOption } from 'another-package'
interface MyOption extends Option { ... }
const myDefaultOption = { ... }
function foo(givenOption: Partial<MyOption>) {
const option = unpartial(givenOption, myDefaultOption, defaultOption)
}
Contribute
npm install
npm run watch