Helpers & utility types for TypeScript projects.
To put type helpers into the global scope:
...or add to your tsconfig's
To expose type helpers as a global
TT namespace, reference
...or put it in your tsconfig as shown above.
A few helpers require a runtime value. This will be an identity or no-op function. Thankfully, these should be removed or inlined by a code minifier and/or the JS VM. These must be imported, because it would be messy to attach them to the global object.
Fortunately, if you're using a supported editor, you can reference them in code and the language service will offer to write the import statement for you.
React-specific helpers should be imported from
These can't be loaded by default because they have a peer dependency on
Until I get around to generating a website from the documentation, use tab-complete in your editor to see the list of helpers and flip through their documentation. Or read the source.
Things already bundled in TypeScript
TypeScript already includes a bunch of type declarations you might not be aware of. Here's an incomplete list:
ArrayLike<T> // Minimal Array interface, without all the obscure methods and Symbols.Partial<T> // T, except all properties are optionalRequired<T> // T, except none of the properties are optionalRecord<K, T> // object-based map from K to TReadonly<T> // T, except all properties are readonlyReadonlyArray<T> // Readonly array. Type system will forbid assignment to items and accessing methods that mutate, like `push()`ReadonlyMap<K, V> // Readonly ECMAScript MapReadonlySet<V> // Readonly ECMAScript SetExtract<T, U> // filter a union type T to only the types that extend UExclude<T, U> // opposite of Extract; filter union T to only the types that *do not* extend UNonNullable<T> // Remove `null` and `undefined` from a union type.ReturnType<F> // Extract the return type of an invokable type (function)InstanceType<C> // Extract the instance type of a `new`-able type (constructor)Pick<T, K> // Grab only properties K of interface T. Useful with `Extract`, `Exclude`, and `keyof`
- add DeepReadonly, DeepMutable, DeepPartial, DeepRequired, DeepNonNullable, DeepNullable (any others?)