NumberThe number type with optional validation checks.
Details
checks holds number-specific constraints, such as int, finite, min, max,
multipleOf, and between checks.
modelsNumberMeta
Source effect/SchemaRepresentation.ts:2135 lines
export interface Number {
readonly Number._tag: "Number"_tag: "Number"
readonly Number.annotations?: Schema.Annotations.Annotations | undefinedannotations?: import SchemaSchema.Annotations.interface Annotations.AnnotationsThis interface is used to define the annotations that can be attached to a
schema. You can extend this interface to define your own annotations.
Details
Note that both a missing key or undefined is used to indicate that the
annotation is not present.
This means that can remove any annotation by setting it to undefined.
Example (Defining your own annotations)
import { Schema } from "effect"
// Extend the Annotations interface with a custom `version` annotation
declare module "effect/Schema" {
namespace Annotations {
interface Annotations {
readonly version?:
| readonly [major: number, minor: number, patch: number]
| undefined
}
}
}
// The `version` annotation is now recognized by the TypeScript compiler
const schema = Schema.String.annotate({ version: [1, 2, 0] })
// const version: readonly [major: number, minor: number, patch: number] | undefined
const version = Schema.resolveAnnotations(schema)?.["version"]
if (version) {
// Access individual parts of the version
console.log(version[1])
// Output: 2
}
Annotations | undefined
readonly Number.checks: ReadonlyArray<Check<NumberMeta>>checks: interface ReadonlyArray<T>ReadonlyArray<type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type NumberMeta =
| {
readonly _tag: "isInt"
}
| {
readonly _tag: "isFinite"
}
| {
readonly _tag: "isMultipleOf"
readonly divisor: number
}
| {
readonly _tag: "isGreaterThanOrEqualTo"
readonly minimum: number
}
| {
readonly _tag: "isLessThanOrEqualTo"
readonly maximum: number
}
| {
readonly _tag: "isGreaterThan"
readonly exclusiveMinimum: number
}
| {
readonly _tag: "isLessThan"
readonly exclusiveMaximum: number
}
| {
readonly _tag: "isBetween"
readonly minimum: number
readonly maximum: number
readonly exclusiveMinimum?:
| boolean
| undefined
readonly exclusiveMaximum?:
| boolean
| undefined
}
Metadata union for number-specific validation checks (int, finite,
min, max, multipleOf, between).
NumberMeta>>
}Referenced by 2 symbols