FIND YOUR NEXT FEW LINES

Results for “type guard”

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

225 snippets foundClear filters
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
GoFunctions & types

Mutate a struct through a pointer receiver

Mutate a struct through a pointer receiver using a complete Go program with explicit sample inputs.

Go✓ Tested
TypeScriptGetting Started

Name a value that stays fixed

TypeScript: Use a constant declaration or the language’s constant naming convention for a fixed limit.

TypeScript✓ Tested
TypeScriptText handling & Unicode

Normalize identifier case consistently

TypeScript: Use toLowerCase for a simple case-insensitive ASCII identifier lookup.

TypeScript✓ Tested
TypeScriptArray traversal & selection

Pair corresponding array items by position

TypeScript: Validate equal lengths before zipping when missing counterparts would be an error.

TypeScript✓ Tested
C#Types & reliable control flow

Parse an enum name without throwing

C#: Combine TryParse and IsDefined when only named declared values should be accepted.

C#✓ Tested
C#Types & reliable control flow

Pass behavior as a function delegate

C#: Func describes a callable with typed parameters and a return value.

C#✓ Tested
TypeScriptRegular expressions & URL encoding

Percent-encode one URL component

TypeScript: encodeURIComponent escapes a parameter value rather than a complete URL.

TypeScript✓ Tested
C#Types & reliable control flow

Perform cleanup even after an exception

C#: A finally block runs after a handled failure as well as after success.

C#✓ Tested
CSSType & reading flow

Preserve line breaks while collapsing repeated spaces

CSS: Pre-line retains newlines but does not preserve all whitespace like pre-wrap does.

CSS✓ Tested
TypeScriptObject behavior & collections

Prevent runtime changes to top-level properties

TypeScript: Object.freeze prevents ordinary top-level mutations; Reflect.set reports the rejected update without throwing.

TypeScript✓ Tested
TypeScriptGetting Started

Print a number with two decimal places

TypeScript: Format a small decimal value consistently for display.

TypeScript✓ Tested