FIND YOUR NEXT FEW LINES
The snippet library.
Small, practical examples. Search by task or narrow things down below.
5 snippets foundClear filters
Describe an object with an interface
Require named fields on a reusable object shape.
interface✓ Tested
Give an optional property a default
Handle missing object fields with nullish coalescing.
optional✓ Tested
Narrow a union using typeof
Handle text and numeric values with separate branches.
union✓ Tested
Return the first item with a generic function
Preserve the element type while allowing empty arrays.
generics✓ Tested
Type a function’s inputs and output
Catch mismatched arguments during compilation.
function✓ Tested