There was an error while loading. Please reload this page.
isOptionalString is a type guard that lets Typescript know that the variable passed in is either a string or undefined.
string
undefined
candidate: unknown
Supply any variable to test if it’s either a string or undefined.
A type predicate for a string (candidate is string | undefined).
candidate is string | undefined
import { isOptionalString } from '@revolutionarygamesco/common' isOptionalString('hello!') // true isOptionalString(undefined) // true isOptionalString(42) // false isOptionalString(['hello!']) // false isOptionalString({ a: 'hello!' }) // false