Skip to content

strict-proxy

Strictly-typed mock object factory via Proxy. Throws a descriptive error when any unmocked property is accessed, preventing silent undefined returns.

The proxy implementation mirrors the design of obsidian-test-mocks/src/internal/strict-proxy.ts.

FunctionDescription
bypassStrictProxyBypasses strict proxy to access the underlying object. If the object is wrapped in a strict proxy, returns the unwrapped target. Otherwise, returns the object as-is. This allows safely accessing optional properties without triggering the proxy’s error on missing props.
strictProxyCreates a strictly-typed mock object from a partial implementation. Uses a Proxy that throws a descriptive error when any unmocked property is accessed, preventing silent undefined returns. - Idempotent: double-wrapping is a no-op. - Passthrough for well-known props (then, toJSON, Symbol.iterator, etc.). - Recursive proxying of nested plain objects.
TypeDescription
StrictProxyPartialA recursive partial type compatible with exactOptionalPropertyTypes. Unlike PartialDeep from type-fest, this type allows full T values at any nesting level via the | T[K] union. This is essential for composing nested strictProxy calls — an inner strictProxy<MetadataCache>(\{...\}) returns MetadataCache, which must be assignable to the outer partial type.