Skip to content

isOptionalObject

Jason Godesky edited this page Aug 15, 2026 · 1 revision

isOptionalObject is a type guard that lets Typescript know that the variable passed in is either an object or undefined.

Warning

isOptionalObject returns false if given null or an array. Usually this is even more useful than a strict type check, but if you’re expecting isOptionalObject to return true for null or an array, this is an edge case to be aware of where we’ve optimized for how we write code for Revolutionary Games over what is strictly true to the language!

Parameters

candidate: unknown

Supply any variable to test if it’s an object or undefined.

Returns

A type predicate for an object (candidate is object | undefined).

Examples

import { isOptionalObject } from '@revolutionarygamesco/common'

isOptionalObject({ a: 1 }) // true
isOptionalObject({}) // true
isOptionalObject(undefined) // true
isOptionalObject(null) // false
isOptionalObject([]) // false
isOptionalObject('hello!') // false
isOptionalObject(42) // false

Clone this wiki locally