Skip to content

isNumber

Jason Godesky edited this page Jul 11, 2026 · 3 revisions

isNumber is a type guard that lets Typescript know that the variable passed in is a number.

Warning

isNumber returns false for NaN. Usually this is even more useful than a strict type check, but if you’re expecting isNumber to return true for NaN, 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 a number or not.

Returns

A type predicate for a number (candidate is number).

Examples

import { isNumber } from '@revolutionarygamesco/common'

isNumber(42) // true
isNumber(0) // true
isNumber(-1) // true
isNumber(Infinity) // true
isNumber(NaN) // false
isNumber('hello!') // false
isNumber('42') // false
isNumber({ a: 1 }) // false
isNumber([]) // false

Clone this wiki locally