hd-utils
Version:
A handy utils for modern JS developers
21 lines (20 loc) • 940 B
TypeScript
import { Primitive } from '../types';
/**
* Tests for one of the [`Primitive`](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) types using the JavaScript [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) operator
*
* Clarification: TypeScript overloads this operator to produce TypeScript types if used in context of types.
*
* @param val The value to be tested
* @returns If `val` is primitive. If used in the flow of the program typescript will infer type-information from this.
*
* @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));
* };
*/
declare const isPrimitive: (val: unknown) => val is Primitive;
export default isPrimitive;