If you are a TypeScript developer, add any of these snippets to Pieces for some extreme time-saving shortcuts. Coding in TypeScript can be challenging and getting used to the intricacies of adding typing to traditional JavaScript can be quite confusing.
This collection of TypeScript examples is aimed at helping you perform common TypeScript and JavaScript operations. No matter your experience level, from beginner to advanced, the following TypeScript code samples will be useful for all developers.
Tags: typescript, pick
How to pick properties from interface in TypeScript
Construct a new type based on partial properties of an interface.
Related links:
Tags: typescript, omit
How to use TypeScript to exclude a property from an interface
Exclude properties from a given interface with this TypeScript snippet.
Related links:
Tags: typescript, get value
How to use TypeScript to get a value of an interface property
Get value of an object with an interface using this TypeScript code sample.
Related links:
Tags: typescript, record
How to store a record as a string with interface in TypeScript
Map a string key to a custom interface in an object.
Tags: typescript, every, collection
How to check if a collection of elements are true in TypeScript
Returns true if all elements in a collection are true.
Tags: typescript, some
How to check if at least one element passes in a function using TypeScript
Tests whether at least one element in the array passes the test implemented by a provided function.
Tags: typescript, filter, compact
How to remove falsy values from an array using TypeScript
Removes falsy values from an array. See our JavaScript snippets collection for the JS version of this TypeScript code snippet.
Related links:
Tags: typescript, async, setTimeout
How to delay async executions using TypeScript
Turns setTimeout into a promise that can be used asynchronously.
Related links:
Tags: typescript, composition
TypeScript function composition
Performs left to right function composition.
Related links:
Tags: typescript, debounce
TypeScript debounce example
Delays invoking a provided function at least since specified milliseconds have elapsed.
Related links:
Tags: typescript, clone, deep clone
How to create a deep clone in TypeScript
These TypeScript code snippets create a deep clone of an object.
Related links:
Tags: typescript, find key
How to find the key that meets a condition in TypeScript
Returns the first key that meets a condition specified from the passed function.
Related links:
Tags: typescript, intersection
Find intersection of two arrays using TypeScript
Returns a list of elements that exist in both arrays.
Tags: typescript, is empty
How to check if an array is empty in TypeScript
Checks if a value is an empty object, array, or null.
Related links:
Tags: typescript, async
How to use Async in TypeScript
Create a promise using Typescript with a void return value.
Tags: typescript, array to object
How to convert object to array in TypeScript
Turns an Array into an Object.