JS Built-ins
TypeScriptbeginner

Type Guard β€” isObject

πŸ“– Usage Example
function isObject(x: unknown): x is Record<string, unknown> {
  return typeof x === 'object' && x !== null
}
isObject({})     // β†’ true
isObject(null)   // β†’ false

A proper isObject guard checks typeof === 'object' AND x !== null, since typeof null is 'object'.

Type Guards: isObject

Challenge: Implement isObject(x: unknown): x is Record<string, unknown>.
Arrays and null should return false.

isObject({})     // β†’ true
isObject([])     // β†’ false  (arrays are not plain objects)
isObject(null)   // β†’ false  (typeof null === 'object' β€” a classic JS gotcha)
πŸ’‘ Hints (1)
  • β€’ Check typeof, exclude null, exclude arrays.