Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unpartial

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unpartial

Unpartial a partialed object

  • 0.6.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
decreased by-6.06%
Maintainers
1
Weekly downloads
 
Created
Source

unpartial

NPM version NPM downloads

Github NodeJS Codecov

Semantic Release

Visual Studio Code Wallaby.js

Unpartial a type.

It is very common to define a config type and Partial<> it in a function argument. When we received the argument, 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(defaultConfig, givenConfig);
  // use config with type safety
}

Code completion is available as you type:

const config = unpartial(defaultConfig, { /* code completion here */});

It also supports merging two default configs. This is useful when you are extending the interface from another 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(defaultOption, myDefaultOption, givenOption)
}

There are 3 more functions available in this library:

  • unpartialRecursively(): unpartial() deeply.
  • required(): an improved version of unpartial() with better type management.
  • requiredDeep(): an improved version of unpartialRecursively() with better type management.

The required() and requiredDeep() function is also exposed in type-plus. Feel free to check it out.

Contribute

# after fork and clone
yarn

# begin making changes
git checkout -b <branch>
yarn watch

# after making change(s)
git commit -m "<commit message>"
git push

# create PR

FAQs

Package last updated on 05 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc