FIND YOUR NEXT FEW LINES
The snippet library.
Small, practical examples. Search by task or narrow things down below.
5 snippets foundClear filters
Handle a result with a discriminated union
Separate success data from an error message.
discriminated union✓ Tested
Read a nested optional value
Avoid dereferencing a missing nested object.
optional chaining✓ Tested
Safely read a caught error
Check the error type before accessing its message.
unknown✓ Tested
Update an object with a readonly input
Create a changed copy while retaining the original.
readonly✓ Tested
Validate an unknown value with a type guard
Check a field before treating unknown data as a typed object.
unknown✓ Tested