Socket
Socket
Sign inDemoInstall

ts-essentials

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-essentials - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

12

dist/types.d.ts

@@ -12,7 +12,17 @@ /** Essentials */

};
/** Like Required but recursive */
export declare type DeepRequired<T> = T extends Primitive ? NonNullable<T> : T extends any[] ? DeepRequiredArray<NonNullable<T[number]>> : T extends {} ? {
[K in keyof T]-?: DeepRequired<NonNullable<T[K]>>;
} : T;
interface DeepRequiredArray<T> extends Array<DeepRequired<T>> {
}
/** Like Readonly but recursive */
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends Array<infer U> ? ReadonlyArray<U> : T extends Function ? T : DeepReadonlyObject<T>;
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends any[] ? DeepReadonlyArray<T[number]> : T extends Function ? T : DeepReadonlyObject<T>;
declare type DeepReadonlyObject<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {
}
/** Make sure that T is not null or undefined */
export declare type NonNullable<T> = T & {};
/** Omit given key in object type */

@@ -19,0 +29,0 @@ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

{
"name": "ts-essentials",
"version": "1.0.0",
"description": "All essential Typescript types in one place",
"keywords": [
"typescript",
"types",
"essentials"
],
"version": "1.0.1",
"main": "dist/index.js",

@@ -17,4 +23,5 @@ "repository": "git@github.com:krzkaczor/ts-essentials.git",

"devDependencies": {
"typescript": "^3.0.3"
"conditional-type-checks": "^0.5.0",
"typescript": "^3.2.2"
}
}

64

README.md

@@ -1,20 +0,41 @@

# ts-essentials
<p align="center">
<img src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/google/146/toolbox_1f9f0.png" width="120" alt="TypeStrict">
<h3 align="center">ts-essentials</h3>
<p align="center">All essential TypeScript types in one place 🤙</p>
<p align="center">
<img alt="Downloads" src="https://img.shields.io/npm/dm/ts-essentials.svg">
<a href="/package.json"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
</p>
</p>
All basic Typescript types in one place 🤙
## Install
```sh
npm add --save-dev ts-essentials
```
or
```sh
yarn add --dev ts-essentials
```
## What's inside?
- [Basic](#basic)
* Primitive
- Primitive
- NonNullable
- [Dictionaries](#dictionaries)
* Dictionary
* DictionaryValues
- [Deep Partial & Deep Readonly](#deep-partial--deep-readonly)
- Dictionary
- DictionaryValues
- [Deep Partial & DeepRequired & Deep Readonly](#deep-partial--deep-required--deep-readonly)
- [Omit](#omit)
- [Opaque types](#opaque-types)
- [Literal types](#literal-types)
- [Exhaustive switch cases in typescript](#exhaustive-switch-cases-in-typescript)
- [Exhaustive switch cases](#exhaustive-switch-cases-in-typescript)
### Basic:
`Primitive` type matching all primitive values
- `Primitive` type matching all primitive values.
- `NonNullable` remove `null` and `undefined` from union type.

@@ -29,3 +50,9 @@ ### Dictionaries

// Use Dictionary type with union string type to make sure to cover all possible values
// Specify second type argument to change dictionary keys type
const dictOfNumbers: Dictionary<string, number> = {
420: "four twenty",
1337: "HAX",
};
// You may specify union types as key to cover all possible cases. It acts the same as Record from TS's standard library
export type DummyOptions = "open" | "closed" | "unknown";

@@ -37,2 +64,3 @@ const dictFromUnionType: Dictionary<number, DummyOptions> = {

};
// and get dictionary values

@@ -42,3 +70,3 @@ type stringDictValues = DictionaryValues<typeof stringDict>;

### Deep Partial & Deep Readonly
### Deep Partial & Deep Required & Deep Readonly

@@ -53,4 +81,5 @@ ```typescript

};
type ComplexObjectPartial = DeepPartial<ComplexObject>;
const sample: ComplexObjectPartial = {
const samplePartial: ComplexObjectPartial = {
nested: {

@@ -61,2 +90,11 @@ array: [{}],

type ComplexObjectAgain = DeepRequired<ComplexObjectPartial>;
const sampleRequired: ComplexObjectAgain = {
simple: 5,
nested: {
a: "test",
array: [],
},
};
type ComplexObjectReadonly = DeepReadonly<ComplexObject>;

@@ -71,3 +109,3 @@ ```

### Opaque
### Opaque types

@@ -95,3 +133,3 @@ ```typescript

### Exhaustive switch cases in typescript
### Exhaustive switch cases

@@ -98,0 +136,0 @@ ```typescript

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