function hasProperty<K extends string>(x: unknown, key: K): x is Record<K, unknown> {
return typeof x === 'object' && x !== null && key in x
}
hasProperty({ name: 'Alice' }, 'name') // β trueThe 'in' operator checks property existence, narrowing to Record<K, unknown> in TypeScript.
Challenge: Implement hasProperty<K extends string>(obj: unknown, key: K): obj is Record<K, unknown> β returning true if obj is a non-null object that has the given key.
hasProperty({ name: 'Alice' }, 'name') // β true
hasProperty({ name: 'Alice' }, 'age') // β false