isPrimitive
Tests for one of the Primitive
types using the JavaScript typeof
operator
Clarification: TypeScript overloads this operator to produce TypeScript types if used in context of types.
@example
const consumer = (value: Primitive | Primitive[]) => {
if (isPrimitive(value)) {
return console.log('Primitive value: ', value);
}
// type of value now inferred as Primitive[]
value.map((primitive) => consumer(primitive));
};
const isPrimitive: (val: unknown) => val is Primitive;