All Projects → LeDDGroup → ts-types-utils

LeDDGroup / ts-types-utils

Licence: MIT license
Type utilities for typescript

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to ts-types-utils

Hoodie
Hoodie is a type safe wrapper around jersey http client
Stars: ✭ 22 (-60%)
Mutual labels:  typesafe
Modern Wasm Starter
🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Stars: ✭ 140 (+154.55%)
Mutual labels:  typesafe
Thread
type safe multi-threading made easier
Stars: ✭ 34 (-38.18%)
Mutual labels:  typesafe
Units Of Measure
Type-safe dimensional analysis and unit conversion in Kotlin.
Stars: ✭ 69 (+25.45%)
Mutual labels:  typesafe
Http4k
The Functional toolkit for Kotlin HTTP applications. http4k provides a simple and uniform way to serve, consume, and test HTTP services.
Stars: ✭ 1,883 (+3323.64%)
Mutual labels:  typesafe
Chaos
The Chaos Programming Language
Stars: ✭ 171 (+210.91%)
Mutual labels:  typesafe
Go Queryset
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.
Stars: ✭ 599 (+989.09%)
Mutual labels:  typesafe
swift-di-explorations
Functional DI explorations in Swift
Stars: ✭ 28 (-49.09%)
Mutual labels:  typesafe
Safe Units
Type-safe TypeScript units of measure 👷📏
Stars: ✭ 137 (+149.09%)
Mutual labels:  typesafe
flutter firestore ref
Cross-platform(including web) Firestore type-safe wrapper.
Stars: ✭ 72 (+30.91%)
Mutual labels:  typesafe
Purescript Graphql
End to End typesafe GraphQL with PureScript
Stars: ✭ 79 (+43.64%)
Mutual labels:  typesafe
Types First Ui
An opinionated framework for building long-lived, maintainable UI codebases
Stars: ✭ 114 (+107.27%)
Mutual labels:  typesafe
Vuex Class Component
A Type Safe Vuex Module or Store Using ES6 Classes and ES7 Decorators written in TypeScript.
Stars: ✭ 189 (+243.64%)
Mutual labels:  typesafe
Mizur
Mizur is a tool to simplify the handling of units, and units coercion/mapping. (it is an evolution of Abacus)
Stars: ✭ 34 (-38.18%)
Mutual labels:  typesafe
SwiftyPods
Type safe pods
Stars: ✭ 15 (-72.73%)
Mutual labels:  typesafe
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+1420%)
Mutual labels:  typesafe
Typedapi
Build your web API on the type level.
Stars: ✭ 165 (+200%)
Mutual labels:  typesafe
typescript-test-utils
Helper types for testing your package exported types
Stars: ✭ 16 (-70.91%)
Mutual labels:  typesafe
HtmlFlow
HtmlFlow Java DSL to write typesafe HTML
Stars: ✭ 119 (+116.36%)
Mutual labels:  typesafe
Flowkit
A declarative type-safe framework for building fast and flexible list with Tables & Collection
Stars: ✭ 215 (+290.91%)
Mutual labels:  typesafe

ts-types-utils

npm version Conventional Commits code style: prettier

Type utilities for typescript

Table of Contents

Usage

npm i -D ts-type-utils
import * as TsTypeUtils from "ts-type-utils";

Match

Match<T, M, F> // T is object, M is what to match to, F negate

Pick from T all properties that match M, or not match M if F is false

import { Match } from "ts-types-utils";

type FunctionProperties<T> = Match<T, Function>; // Match<T, Function, true>
type NonFunctionProperties<T> = Match<T, Function, false>;

type Foo = {
  a: string;
  b: number;
  c: () => void;
  d: (hello: string) => number;
};

const nonfuncs: NonFunctionProperties<Foo>; // { a: string, b: number }
const funcs: FunctionProperties<Foo>; // { c: () => void; d: (hello: string) => number }

MatchNames

MatchNames<T, M, F> // T is object, M is what to match to, F negate

Get properties names from T that match M, or not match M if F is false

import { MatchNames } from "ts-types-utils";

type FunctionPropertiesNames<T> = MatchNames<T, Function>; // MatchNames<T, Function, true>
type NonFunctionPropertiesNames<T> = MatchNames<T, Function, false>;

type Foo = {
  a: string;
  b: number;
  c: () => void;
  d: (hello: string) => number;
};

const nonfuncs: NonFunctionPropertiesNames<Foo>; // "a" | "b"
const funcs: FunctionPropertiesNames<Foo>; // "c" | "d"

Assign

Assign<A, B> like A & B but replaces intersected A types with the ones from B

import { Assign } from "ts-types-utils";

type A = {
  foo: string;
  bar: number;
};
type B = {
  foo: number;
  baz: boolean;
};

const bad: A & B = {
  foo: 1, // error type string | number doesn't match number
  bar: 2,
  baz: false
};
const good: Assign<A, B> = {
  foo: 1,
  bar: 2,
  baz: false
};

Func

Func<P, R> // P: params type, R: return type

This doesn't really bring much but syntactic sugar

import { Func } from "ts-types-utils";

const myfunc: Func<[string, number], boolean>; // (a: string, b: number) => boolean

PromiseOr

PromiseOr<T> = T | Promise<T>

Why? Because it gets cumbersome having to repeat long types again and again. I've found myself using this a lot, specially in interfaces (for greater flexibility).

export function test(): Promise<string> | string { ... }

Can be simplified to

export function test(): PromiseOr<string> { ... }

Action

Action<T = void> = () => Action

Why? Because it gets tiring and makes the code less clear having to write function types.

export function invoke(callback: () => string)): void { ... }

export function invoke(callback: () => string | number | object)): void { ... }

export function invoke(callback: () => boolean | object)): () => boolean | string { ... }

Can be simplified to

export function invoke(callback: Action<string>)): void { ... }

export function invoke(callback: Action<string | number | object>): void { ... }

export function invoke(callback: Action<boolean | object>):  Action<boolean | string> { ...

UndefinedToOptional

UndefinedToOptional<T>
import { UndefinedToOptional } from "ts-types-utils";

interface Options {
  times: number | undefined
}
function foo(options: Options) {}
foo({}) // Error expected times

function bar(options: UndefinedToOptional<Options>) {}
bar({}) // Good: times is optional now

UndefinedToOptional<Options> // { times?: number }

ArgsType ( DEPRECATED: already in std types as Parameters )

ArgsType<F> // F is function

Like built-in ReturnType but for the args of a function, works for any number of arguments

import { ArgsType } from "ts-types-utils";
function myFunc(a: string, b: number) {}
const all: ArgsType<typeof myFunc>; // [string, number]
const first: ArgsType<typeof myFunc>[0]; // string
const second: ArgsType<typeof myFunc>[1]; // number

Related

Tests were made with typescript-test-utils

Contributors

  • @danielpa9708
  • @cloudrex
  • @luisenrike
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].