FIND YOUR NEXT FEW LINES

Results for “common”

Small, practical examples. Search by task or narrow things down below.

142 snippets foundClear filters
TypeScriptTypes & functions

Give an optional property a default

Handle missing object fields with nullish coalescing.

optional✓ Tested
TypeScriptObject behavior & collections

Group records into map entries

TypeScript: Initialize an array for a missing Map key before appending its values.

TypeScript✓ Tested
TypeScriptSafe data handling

Handle a result with a discriminated union

Separate success data from an error message.

discriminated union✓ Tested
TypeScriptGetting Started

Handle three possible outcomes

TypeScript: Check high, normal and low values with an ordered conditional chain.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Inspect both successful and failed promise results

TypeScript: allSettled preserves input order and reports failures without rejecting the combined promise.

TypeScript✓ Tested
TypeScriptRegular expressions & URL encoding

Inspect the parsed pieces of a URL

TypeScript: Use URL properties rather than splitting a URL at punctuation.

TypeScript✓ Tested
TypeScriptArray traversal & selection

Iterate with array indices and values

TypeScript: entries provides each position and value without a separate counter.

TypeScript✓ Tested
TypeScriptArray restructuring

Keep both matching and rejected values

TypeScript: Use two explicit outputs when a caller needs both sides of a classification.

TypeScript✓ Tested
TypeScriptObject behavior & collections

List an object’s own enumerable keys

TypeScript: Object.keys omits inherited and non-enumerable properties.

TypeScript✓ Tested
GitMerging & replaying changes

List paths changed on a feature branch since its merge base

Git: A three-dot diff compares the branch tip with the common ancestor.

Git✓ Tested
TypeScriptArray restructuring

Map items to multiple output values

TypeScript: flatMap combines mapping and a one-level flattening operation.

TypeScript✓ Tested
TypeScriptGetting Started

Measure a short text value

TypeScript: Read the length of an ASCII string. Non-ASCII text may use multiple code units or bytes depending on the language.

TypeScript✓ Tested