/** * Safely narrow unknown object and infer property existence * @param obj * @param key */ export function hasProp( obj: unknown, key: K | null | undefined ): obj is Record { return key != null && obj != null && typeof obj === "object" && key in obj; }