import { HasTag, SomeSpec, Spec, SpecKind, SpecSuccess, SpecTag, SpectypesError } from './types.js' import { error } from './error.js' /** * Creates a spec with custom constraint. * * @param spec Basis spec * @param constraint Function that performs additional validation */ export const limit: < Constraint extends (value: SpecSuccess) => boolean, ItemSpec extends Spec = SomeSpec >( spec: HasTag extends true ? SpectypesError<'optional', 'limit'> : HasTag extends true ? SpectypesError<'filter', 'limit'> : HasTag extends true ? SpectypesError<'lazy', 'limit'> : ItemSpec, constraint: Constraint ) => Spec< ['limit', ...SpecTag], SpecKind, // eslint-disable-next-line @typescript-eslint/no-explicit-any Constraint extends (value: any) => value is infer U ? U : SpecSuccess > = error