Typed Object.keys and Object.entries
Helpers that keep key types instead of widening to string, for objects you know the shape of.
Typed helpers, generics and type-safe patterns.
Loading snippets…
14 snippets
Helpers that keep key types instead of widening to string, for objects you know the shape of.
An event emitter whose event names and payloads are checked by the compiler through a generic map type.
Validate a config object against an interface while keeping its precise literal types.
Safely turn unknown JSON into a typed result by validating its shape instead of casting.
Encode "at least one element" in the type so head, max and similar functions never see an empty array.
Group an array into a Record by a property or function while keeping the item type.
A fetch wrapper that throws on HTTP errors and validates the JSON body with a type guard.
A debounce function whose returned function keeps the parameter types and exposes cancel() and flush().
Prevent mixing up UserId and OrderId strings by giving each a unique compile-time brand.
An assertion function that narrows away null and undefined and throws a clear error otherwise.
Copy selected keys from an object (or drop some) with return types that match at compile time.
Model success and failure as a discriminated union so callers must handle both cases.