This package offers a suite of versatile utility types that simplify common tasks, improve type safety, and boost productivity.
- Easy to use
- Zero third party dependencies
- Type level only
- No more copy paste "type definitions" between projects
# NPM
npm install --save-dev typelab
# BUN
bun add -d typelabHere is an example for some types from each categories.
Aliases
Primitiveconstvalue1: Primitive="";// validconstvalue2: Primitive={};// invalid
Nullableconstexample: Nullable<string>=null;// validconstexample2: Nullable<string>=undefined;// invalid
Undefinableconstexample: Undefinable<string>=undefined;// validconstexample2: Undefinable<string>=null;// invalid
Assertions
IsExtendstypeExtends=IsExtends<'',string>;// truetypeNotExtends=IsExtends<string,''>;// false
IsEqualtypeEqual=IsEqual<string,string>;// truetypeNotEqual=IsEqual<string,''>;// false
IsAnytypeValid=IsAny<any>;// truetypeInvalid=IsAny<string>;// false
Conditions
IfExtendstypeYes=IfExtends<'',string,'yes','no'>;// 'yes'typeNo=IfExtends<string,'','yes','no'>;// 'no'typeYesOrNo=IfExtends<string|number,string,'yes','no'>;// 'yes' | 'no'
IfEqualtypeYes=IfEqual<string,string,'yes','no'>;// 'yes'typeNo=IfEqual<string,number,'yes','no'>;// 'no'
IfAnytypeYes=IfAny<any,'yes','no'>;// 'yes'typeNo=IfAny<string,'yes','no'>;// 'no'
Utils
FunctionCallbackify// (a: string, callback: (error: unknown, result: string) => void) => voidtypeCallbackified=FunctionCallbackify<(a: string)=>Promise<string>>;
FunctionPromisify// Callback-style function:// (a: string) => Promise<string>typePromisified=FunctionPromisify<(a: string,callback: (error: Error,result: string)=>void)=>void>;// Regular function:// (a: string) => Promise<string>typePromisifiedFn=FunctionPromisify<(a: string)=>string>;
ObjectAssign// { a: string; b: string; c: boolean }typeAssign1=ObjectAssign<{a: string;b: number},{b: string;c: boolean}>;// { a: string; 0: string }typeAssign2=ObjectAssign<{a: string},[string]>;// { [x: number]: string, a: string }typeAssign3=ObjectAssign<{a: string},string[]>;// [number, number]typeAssign4=ObjectAssign<[string],[number,number]>;// (string | number)[]typeAssign5=ObjectAssign<string[],[number,number]>;// (string | number)[]typeAssign6=ObjectAssign<string[],number[]>;// [number, string]typeAssign7=ObjectAssign<[string],{0: number;1: string}>;// (string | number)[]typeAssign8=ObjectAssign<[number],'str'>;// { [x: number]: string, a: string }typeAssign9=ObjectAssign<{a: string},'str'>;
A complete reference for all available reusable types.
Aliases
Arrays
Array · Arr · List · ReadonlyArray · ReadonlyArr · ReadonlyList · WritableArray · WritableArr · WritableListTuples
ReadonlyTuple · Tuple · WritableTupleFunctions
AsyncFn · AsyncFunction · Fn · Function · NewableFn · NewableFunctionObjects
ObjectArrayLike · ObjectEmpty · ObjectGenericMisc
Any · Async · Class · Falsy · Infinity · NegativeInfinity · NonNullish · Nullish · Nullable · Primitive · PositiveInfinity · Undefinable · Void
Assertions
Arrays
IsArray · IsArrayReadonly · IsArrayWritableTuples
IsTuple · IsTupleReadonly · IsTupleWritableFunctions
IsAsyncFunction · IsFunction · IsNewableFunctionObjects
IsObject · IsObjectArrayLike · IsObjectEmpty · IsObjectLiteral · IsOptionalProperty · IsRequiredPropertyPrimitives
IsBigInt · IsBoolean · IsFalse · IsNull · IsNumber · IsNumberDecimal · IsNumberInteger · IsNumberLiteral · IsPrimitive · IsString · IsStringLiteral · IsSymbol · IsTrue · IsUndefinedComparisons
IsAssignable · IsAssignableEitherWay · IsAssignableMutually · IsEqual · IsExtends · IsNotAssignable · IsNotAssignableEitherWay · IsNotAssignableMutually · IsNotEqual · IsNotExtendsMisc
IsAny · IsClass · IsFalsy · IsIntersected · IsNever · IsNonNullish · IsNullish · IsPositive · IsPropertyKey · IsPromise · IsTruthy · IsUnion · IsUndefinable · IsUnknown · IsVoid
Conditions
Arrays
IfArray · IfArrayReadonly · IfArrayWritableTuples
IfTuple · IfTupleReadonly · IfTupleWritableFunctions
IfAsyncFunction · IfFunction · IfNewableFunctionObjects
IfObject · IfObjectArrayLike · IfObjectEmpty · IfObjectLiteral · IfOptionalProperty · IfRequiredPropertyPrimitives
IfBigInt · IfBoolean · IfFalse · IfNull · IfNumber · IfNumberDecimal · IfNumberInteger · IfNumberLiteral · IfPrimitive · IfString · IfStringLiteral · IfSymbol · IfTrue · IfUndefinedComparisons
IfAssignable · IfAssignableEitherWay · IfAssignableMutually · IfEqual · IfExtends · IfNotAssignable · IfNotAssignableEitherWay · IfNotAssignableMutually · IfNotEqual · IfNotExtendsMisc
IfAny · IfClass · IfFalsy · IfIntersected · IfNever · IfNonNullish · IfNullish · IfPositive · IfPropertyKey · IfPromise · IfTruthy · IfUnion · IfUndefinable · IfUnknown · IfVoid
Utils
Arrays
ArrayLength · ArrayElements · ArrayValues · ArrayIndexes · ArrayAt · ArrayFirst · ArrayLast · ArrayConcat · ArrayPush · ArrayPop · ArrayUnshift · ArrayShift · ArrayFlat · ArrayTake · ArraySkip · ArrayRequired · ArrayPartial · ArrayRequiredIndexes · ArrayOptionalIndexes · ArrayRequiredElements · ArrayOptionalElements · ArrayRequiredValues · ArrayOptionalValues · ArrayOmitRequired · ArrayOmitOptional · ArrayToObject · ArrayAssign · ArrayOverwrite · ArrayMerge · ArrayUnionizeObjects
ObjectPick · ObjectRequired · ObjectPartial · ObjectRequiredKeys · ObjectOptionalKeys · ObjectOmitRequired · ObjectOmitOptional · ObjectReadonly · ObjectWritable · ObjectPath · ObjectPathValue · ObjectToTuple · ObjectAssign · ObjectOverwrite · ObjectMerge · ObjectUnionizeFunctions
FunctionAssign · FnAssign · FunctionOverwrite · FnOverwrite · FunctionMerge · FnMerge · FunctionPromisify · FnPromisify · FunctionCallbackify · FnCallbackifyUnions
UnionToIntersection · UnionLast · UnionPop · UnionIntersection · UnionExclusive · UnionToTupleParsing
ParseInt · ParseIntNegative · ParseIntPositive · ParseFloat · ParseFloatNegative · ParseFloatPositive · ParseBigInt · ParseBigIntNegative · ParseBigIntPositive · ParseString · ParseBoolean · ParseObjectMisc
Brand · Detailed · ExcludeNullish · ExcludeNull · ExcludeUndefined · ExtractArray · ExtractPromise · ExtractParams · ExtractReturn · KeyOf · Mapped · PropValue · Toggle · ValueOf
- Typescript
Strongly typed programming language that builds on JavaScript. - Bun
All-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.
The code in this project is released under the MIT License.