-
This structure guarantees to return a string. Itβs super useful for all kinds of functionality like algebraic type specification where a neutral value is required by design.
const safeRecord = new Proxy( {}, { get: (handler: Record<PropertyKey, string>, name: PropertyKey) : string => { handler[name] ??= ""; return handler[name]; } } );
~ 63 words