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

simplytyped

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplytyped

yet another Typescript type library for advanced types

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.8K
decreased by-50.99%
Maintainers
1
Weekly downloads
 
Created
Source

SimplyTyped

Yet another typing library. This differs by aiming to be less experimental than others, driven by industry use cases.

Many of the exposed types are a very thin layer above built in functionality. The goal is to provide all of the building blocks necessary to make concise, yet complex types.

Conditionals

Some (somewhat common) implementations of conditional type logic

If

type x = If<True, string, number> // => string
type y = If<False, string, number> // => number

And

type x = If<And<True, True>, string, number> // => string
type y = If<And<True, False>, string, number> // => number
...

Or

type x = If<Or<True, False>, string, number> // => string
type y = If<Or<False, False>, string, number> // => number
...

Not

type x = Not<True> // => False
type y = Not<False> // => True

Objects

type obj1 = { w: string, x: string, y: number }
type obj2 = { y: string, z: number }

Keys

No different than keyof, but can look a bit nicer when nesting many types deep

type x = keyof obj1 // => 'w' | 'x' | 'y'
type y = Keys<obj1> // => 'w' | 'x' | 'y'

ObjectType

On its own, not that interesting. Takes an object and makes it an object type. Is useful when combined with & intersection types (as seen next).

type x = ObjectType<obj1> // => { w: string, x: string, y: number }

CombineObjects

Takes the intersection between two objects, and flattens them. This can make extremely complex types look much nicer.

type x = obj1 & obj2 // => { w: string, x: string, y: number } & { y: string, z: number }
type y = CombineObjects<obj1, obj2> // => { w: string, x: string, y: string & number, z: number }

SharedKeys

Gets all of the keys that are shared between two objects (as in keys in common).

type x = SharedKeys<obj1, obj2> // => 'y'

DiffKeys

Gets all of the keys that are different from obj1 to obj2.

type x = DiffKeys<obj1, obj2> // => 'w' | 'x'
type y = DiffKeys<obj2, obj1> // => 'z'

AllKeys

Gets all keys between two objects.

type x = AllKeys<obj1, obj2> // => 'w' | 'x' | 'y' | 'z'

Omit

Gives back an object with listed keys removed.

type x = Omit<obj1, 'w' | 'x'> // => { y: number }

Merge

Much like _.merge in javascript, this returns an object with all keys present between both objects, but conflicts resolved by rightmost object.

type x = Merge<obj1, obj2> // => { w: string, x: string, y: string, z: number }

DeepPartial

Uses Partial to make every parameter of an object optional (| undefined).

type x = DeepPartial<obj1> // => { w?: string, x?: string, y?: number }

Tuples

A tuple can be defined in two ways: [number, string] which as of Typescript 2.7 has an enforced length type parameter: [number, string]['length'] === 2 or using this libraries Tuple<any> which can be extended with any length of tuple: function doStuff<T extends Tuple<any>>(x: T) {}.

Tuple

function doStuff<T extends Tuple<any>>(x: T) {}

doStuff(['hi', 'there']); // => doStuff(x: ['hi', 'there']): void

UnionizeTuple

type x = UnionizeTuple<[number, string]> // => number | string

Strings

Diff

Get the differences between two unions of strings.

type x = Diff<'hi' | 'there', 'hi' | 'friend'> // => 'there'

Keywords

FAQs

Package last updated on 07 Dec 2017

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