1.0.5 • Published 2 years ago

@wowissu/types v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@wowissu/types

general

IfEquals<X, Y, A=X, B=never>

Compare fst. and snd. generic type and return thr. or fth.

type R = IfEquals<number, number, number, string>; // number
type R = IfEquals<string, string>; // string
type R = IfEquals<number, string, number, string>; // string
type R = IfEquals<number, string, number>; // never

WritableKeys<T>

Pick the keys of writable member.

type R = WritableKeys<{ readonly foo: 'foo', bar: 'bar', foobar: 'foobar' }>;
type R = "bar" | "foobar"

ReadonlyKeys<T>

Pick the keys of readonly member.

type R = ReadonlyKeys<{ readonly foo: 'foo', bar: 'bar', foobar: 'foobar' }>;
type R = "foo"

UnionToIntersection<T>

Turn Union To Intersection

type R = UnionToIntersection<A | B>
type R = A & B

function

FirstArgument<T>

Return the first parameter

type Result = FirstArgument<(fst: number, sed: string, thr: object) => any>; // number
type Result = number

OmitFirstParamters<T>

Return the rest after first parameter

type Result = OmitFirstParamters<(fst: number, sed: string, thr: object) => any>;
type Result = [sed: string, thr: object]

object

ValueOf<T>

Get values type.

type Result = Valueof<{ foo: string, bar: number }>; // string | number

KeysOfType<T, TProp>

Get type matched keys.

type Result = KeysOfType<{ foo: string, bar: number }, string>; // 'foo'

FilterOfType<T, TProp>

Get filter members by type.

type Result = FilterOfType<{ foo: string, bar: number }, string>; // { foo: string }

RequireAtLeastOne<T, K extends keyof T>

Require at least one member from T

type Target = { foo?: string, bar?: number, other: string }
type TargetLeastOne = RequireAtLeastOne<Target, 'foo' | 'bar'>

// passed
const objA: TargetLeastOne = { foo: 'foo', other: 'other' };
const objB: TargetLeastOne = { bar: 0, other: 'other' };

ArrayElement<T>

Get type of element from array

type Result = ArrayElement<[ number, string ]> => number | string

ArrayElementMemberType<T, M>

Get type from member in element of array

type TodoList = Array<{ foo: number, bar: string }>
type Result = ArrayElementMemberType<TodoList, 'foo'> // number

promise

Await<T>

Get type from Promise<T>

type Result = Await<Promise<string>> === string

AwaitReturnType<T>

Get type from call who return the Promise

type Resoult = AwaitReturnType<() => Promise<string>> === string
1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago