A custom type guard to check if an object has a specific optional property.
13 weeks ago
function hasProperty<T extends object, K extends PropertyKey>( obj: T, key: K ): obj is T & Record<K, unknown> { return key in obj; }