Skip to main content

Primitive

Primitive = string | number | boolean | symbol | bigint | null | undefined

Union of all JavaScript primitive types.

Useful for type guards and generic constraints.

Sinceโ€‹

2.0.0


Exampleโ€‹

function isPrimitive(value: unknown): value is Primitive {
return value === null || (typeof value !== "object" && typeof value !== "function");
}

isPrimitive("hello"); // true
isPrimitive(42); // true
isPrimitive({}); // false
isPrimitive([]); // false