tsdef
TypeScript common patterns shortcuts definitions snippets utility gist library
Get Started
npm install -D tsdef
or
yarn add -D tsdef
How to Use
; ; // ok ; // error
Source Code)
Documentation (; ;;; ;;;;;; // removes both null or undefined from T; // removes null from T; // removes undefined from T; // make all properties nilable; // make all properties nullable; // make all properties undefinable; // make all properties non nilable; // make all properties non null; // make all properties non undefined; // make all properties required; // make all properties non readonly; // string | number | symbol; // matches any functions; // matches any constructors; // matches classes // matches prototypes // matches any objects // matches objects with string keys // matches objects with number keys // without some keys; // values of object; // get a property; // get keys with values of given type; // get keys with values of given sub type// For some reason, this works and KeyOfType doesn't when U = undefined; // make some keys optional; // make some keys nilable; // make some keys nullable; // make some keys undefinable; // make some keys non nil; // make some keys non null; // make some keys non undefined; // make all properties optional recursively including nested objects.// keep in mind that this should be used on json / plain objects only.// otherwise, it will make class methods optional as well.; // first object properties excluding common keys with second object; // union of two objects; // similar to Object.assign; // get arguments type; // get arguments type; // get return value type; // get return type if a function, otherwise return itself; // get instance type of class; // get promise return type// PromisedType<Promise<T>> = T; // get promise return type if promise, otherwise return itself// MaybePromisedType<T | Promise<T>> = T; // get promise return type; // get array item type; // get thunk for type; // get thunk or self; // get return type of thunk; // get return type if thunk, otherwise get self; // get inferred type of array item or return value or promised value; // InheritClass<C1, C2>: class C1 extends C2 {}; // return Then if T is not null nor undefined, otherwise return False// test null and undefined separately to prevent side effect from args distribution; // return True if T is not null, otherwise return False; // return True if T is not undefined, otherwise return False; // return True if T is `never`, otherwise return False// wrap with array to prevent args distributing; // return True if T is `any`, otherwise return False; // return True if T is `unknown`, otherwise return False; // return True if T strictly includes U, otherwise return False; // tests and returns True if they are equal, False otherwise.// wrap with array and do both ways to prevent args distrubition; // tests and returns True if both objects have same keys, False otherwise.; // https://github.com/Microsoft/TypeScript/issues/26051;// U extends Exact<{ [K in keyof T]-?: (v: T[K]) => any }, U>
Contribute
Pull Requests are welcome!
Just try to be consistent with existing naming conventions and coding styles.
Names must be concise, easy to read, and precisely descriptive.
I've setup prettier, so make sure your codes are auto formatted according to my prettier setup.