New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bedard/types

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedard/types

[![Test status](https://img.shields.io/github/workflow/status/scottbedard/types/Test)](https://github.com/scottbedard/types/actions/workflows/test.yml) [![Dependencies](https://img.shields.io/david/scottbedard/types)](https://david-dm.org/scottbedard/type

  • 0.2.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@bedard/types

Test status Dependencies Dev dependencies License

The goal of this package is to act as an extension to Typescript's built-in utility types. There is currently no runtime, but that may change if type guards are added. I don't anticipate breaking changes, but with that said this is mainly for personal use, so upgrade with caution.

Installation

The recommended way to install this package is through NPM.

npm install @bedard/types

Utility types

Difference<A, B>

Elements of A that are not elements of B. For unions, this is the same as the Exclude utility.

import { Difference } from '@bedard/types'

type Left = Difference<{ a: any, b: any }, { b: any, c: any }> // { a: any }

Equal<A, B>

Types true if A and B are equal. This is mainly used with Expect to verify that types are working as expected. See NotEqual for the inverse of this type.

import { Expect, Equal } from '@bedard/types'

type Test = Expect<Equal<number, number>>

Expect<T>

Verify that T is true. This allows for assertions to be made using the type system. See Equal and NotEqual for more usage examples.

import { Expect } from '@bedard/types'

type Test = Expect<true>

Intersection<A, B>

The intersection of A and B, giving preference to A.

import { Intersection } from '@bedard/types'

type Shared = Intersection<{ a: any, b: number }, { c: string, d: any }> // { b: number }

Join<Parts, Delimeter>

Join Parts by Delimeter. This type is the opposite of Split.

import { Join } from '@bedard/types'

type Str = Join<['a', 'b', 'c']> // 'abc'

type Parts = Join<['a', 'b', 'c'], '.'> // 'a.b.c'

NotEqual<A, B>

Types true if A does not equal B. This type is mainly used with Expect to verify that types are working as expected. See Equal for the inverse of this type.

import { Expect, NotEqual } from '@bedard/types'

type Test = Expect<NotEqual<number, string>>

Shift<T>

Remove the first element from T.

import { Shift } from '@bedard/types'

type Tail = Shift<['foo', 'bar', 'baz']> // ['bar', 'baz']

Split<Source, Delimeter>

Split Source by Delimeter. This type is the opposite of Join.

import { Split } from '@bedard/types'

type Characters = Split<'abc'> // ['a', 'b', 'c']

type Parts = Split<'a.b.c', '.'> // ['a', 'b', 'c']

SymmetricDifference<A, B>

The symmetric difference of A and B.

import { SymmetricDifference } from '@bedard/types'

type OuterSet = SymmetricDifference<'a' | 'b', 'b' | 'c'> // 'a' | 'c'

type OuterObj= SymmetricDifference<{ a: any, b: any }, { b: any, c: any }> // { a: any, c: any }

ValueOf<T>

Generate a union from the values of T. This can be thought of as an opposite to the keyof operator.

import { ValueOf } from '@bedard/types'

type Values = ValueOf<{ foo: number, bar: string }> // number | string

Without<A, B>

Prohibit properties of A and omit properties of B.

import { Without } from '@bedard/types'

type FooWithoutBar = Without<{ foo: any, bar: any }, { bar: any }> // { foo?: never }

XOR<A, B>

Create an exclusive or between two types. Note that for objects, this differs from a union type in that keys are strictly matched.

import { XOR } from '@bedard/types'

type FooOrBar = XOR<{ foo: any }, { bar: any }>

const a: FooOrBar = { foo } // pass
const b: FooOrBar = { bar } // pass
const c: FooOrBar = { foo, bar } // fail

FAQs

Package last updated on 20 Sep 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