253
254
export function validateConstraints(args: unknown[], constraints: Array<TypeConstraint | undefined>): void {
255
>
const len = Math.min(args.length, constraints.length);
types.ts
256
>
for (let i = 0; i < len; i++) {
257
>
validateConstraint(args[i], constraints[i]);
258
>
}
259
>
}
260
261
export function validateConstraint(arg: unknown, constraint: TypeConstraint | undefined): void {
263
>
if (isString(constraint)) {
264
if (typeof arg !== constraint) {
265
throw new Error(`argument does not match constraint: typeof ${constraint}`);
266
}
267
>
} else if (isFunction(constraint)) {
types.ts
268
>
try {
269
>
if (arg instanceof constraint) {
270
return;
271
}
273
// ignore
274
}
275
>
// eslint-disable-next-line local/code-no-any-casts
types.ts
276
>
if (!isUndefinedOrNull(arg) && (arg as any).constructor === constraint) {
277
>
return;
278
>
}
279
>
if (constraint.length === 1 && constraint.call(undefined, arg) === true) {
280
return;
281
}
282
>
throw new Error(`argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true`);
types.ts
283
>
}
284
>
}
285
286
/**