Socket
Socket
Sign inDemoInstall

react-redux-typescript

Package Overview
Dependencies
1
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-redux-typescript

React / Redux / TypeScript Utils


Version published
Weekly downloads
2.2K
increased by0.22%
Maintainers
1
Install size
88.5 kB
Created
Weekly downloads
 

Readme

Source

React / Redux / TypeScript Utils

Utility belt for React + Redux + TypeScript Projects

  • Semantic Versioning
  • Output separate bundles for your specific workflow needs:
    • ES5 + CommonJS - main
    • ES5 + ES-Modules - module
    • ES2015 + CommonJS - jsnext:main

Table of Contents (v3.0)

Redux Actions Utils

For advanced docs check here: https://github.com/piotrwitek/ts-redux-actions

Mapped Types

Type Utils


Archived docs:


Redux Actions Utils

createAction

https://github.com/piotrwitek/ts-redux-actions#createaction

createAction(typeString, creatorFunction?)
typeString: TS extends string,
creatorFunction: (...args: any[]) => { type: TS, payload?: P, meta?: M, error?: boolean }
return: (
  (...args: any[]) => { type: TS, payload?: P, meta?: M, error?: boolean }
) & { readonly type: TS }

Mapped Types

DiffKeys

Return a difference of non-related string literal unions

type DiffKeys<T extends string, U extends string>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }
interface Props { a: number, d: number }

type Diffed_Keys = DiffKeys<keyof Props, keyof Props2>;
// Expect: 'b' | 'c'

OmitKeys

Omit part of string literal union with constraint to existing literals

type OmitKeys<T extends string, U extends T>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }

type Omitted_Keys = OmitKeys<keyof BaseProps, 'a'>;
// Expect: 'b' | 'c'

Diff

Return an object containing non-intersecting properties of non-related objects

type Diff<T extends object, U extends object>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }
interface Props { a: number, d: number }

type Diffed_Props = Diff<BaseProps, Props>;
// Expect { b?: number | undefined, c: boolean }

Omit

Omit object property with constraint to existing keys

type Omit<T extends object, K extends keyof T>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }

type Omitted_Props = Omit<BaseProps, 'a'>;
// Expect: { b?: number | undefined, c: boolean }

Overwrite

Overwrite intersecting properties from to

type Overwrite<T extends object, U extends object>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }
interface Props { a: number, d: number }

type Overwritten_Props = Overwrite<BaseProps, Props>;
// Expect: { a: number, b?: number | undefined, c: boolean }

Assign

Assign properties from to (overwrite intersecting)

type Assign<T extends object, U extends object>

Usage:

interface BaseProps { a: string, b?: number, c: boolean }
interface Props { a: number, d: number }

type Assigned_Props = Assign<BaseProps, Props>;
// Expect: { a: number, b?: number | undefined, c: boolean, d: number }

Type Utils

getReturnOfExpression

Get return value of an "expression" with inferred return type
Alias: returntypeof https://github.com/Microsoft/TypeScript/issues/6606

// this polyfill exist because TypeScript does not support getting type of expression 
// (tracking issue: https://github.com/Microsoft/TypeScript/issues/6606)
function getReturnOfExpression<T>(
  expression: (...params: any[]) => T,
): T;

// Example:
import { getReturnOfExpression } from 'react-redux-typescript';

const increment = () => ({ type: 'INCREMENT' as 'INCREMENT' });

const returnOfIncrement = getReturnOfExpression(increment);
type INCREMENT = typeof returnOfIncrement; // { type: "INCREMENT"; }

MIT License

Copyright (c) 2016 Piotr Witek piotrek.witek@gmail.com (http://piotrwitek.github.io)

Keywords

FAQs

Last updated on 24 Nov 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc