shapeit
Version:
Object validation tools for Javascript and, specially, Typescript
17 lines (16 loc) • 578 B
TypeScript
import { PrimitiveOrGuard, GuardType } from '../types/guards';
import { NonEmptyArray } from '../types/utils';
/**
* Creates a guard for a union type from primitive names or other guards
*
* @example
* const isValid = oneOf('string', is('number'));
*
* if (isValid(input)) {
* doSomethingWith(input); // input is typed as string | number
* }
* else {
* console.error(isValid.errors); // Errors found
* }
*/
export default function oneOf<T extends NonEmptyArray<PrimitiveOrGuard<unknown>>>(...types: T): import("../types/guards").Guard<GuardType<T[number]>>;