Class SetShape<ValueShape>

The shape of a Set instance.

Type Parameters

  • ValueShape extends AnyShape

    The value shape.

Hierarchy (view full)

Implements

Constructors

Properties

_options: undefined | IssueOptions | Message

The type issue options or the type issue message.

annotations: Dict<any> = {}

The dictionary of shape annotations.

inputs: readonly unknown[]

The array of unique input types and values that are accepted by the shape.

isAsync: boolean

true if the shape allows only Shape.parseAsync and throws an error if Shape.parse is called, or false if the shape can be used in both sync and async contexts.

isCoercing: boolean = false

true if this shape coerces input values to the required type during parsing, or false otherwise.

operations: readonly Operation[] = []

The array of operations that are applied to the shape output.

valueShape: ValueShape

The value shape.

Methods

  • Returns input types and literal values that this shape can accept as an input.

    Returns readonly unknown[]

  • Must return true if the shape must be used in async context only, otherwise the shape can be used in both sync and async contexts. Override this method to implement a custom shape.

    Returns boolean

  • Returns true if the shape accepts given input type or value, or false otherwise.

    Parameters

    • input: unknown

      The type or value that must be checked.

    Returns boolean

  • Adds annotations to the shape.

    Parameters

    • annotations: ReadonlyDict<any>

      Annotations to add.

    Returns this

    The clone of the shape with the updated annotations.

  • Returns a sub-shape that describes a value associated with the given property name, or null if there's no such sub-shape.

    Parameters

    • key: unknown

    Returns null | AnyShape

    The sub-shape or null if there's no such key in the shape.

  • Enables an input value coercion.

    Returns this

    The clone of the shape.

  • Asynchronously parses the value.

    Parameters

    • input: unknown

      The value to parse.

    • Optionaloptions: ParseOptions

      Parsing options.

    Returns Promisify<Set<Output<ValueShape>>>

    The promise that resolves with the value that conforms the output type of the shape, or rejects with a ValidationError if any issues occur during parsing.

  • Asynchronously parses the value and returns undefined value if parsing fails.

    Parameters

    • input: unknown

      The value to parse.

    Returns Promisify<undefined | Set<Output<ValueShape>>>

    The value that conforms the output type of the shape.

  • Asynchronously parses the value and returns the default value if parsing fails.

    Type Parameters

    • DefaultValue

      The default value that is returned if parsing fails.

    Parameters

    • input: unknown

      The value to parse.

    • defaultValue: DefaultValue

      The default value that is returned if parsing fails.

    • Optionaloptions: ParseOptions

      Parsing options.

    Returns Promisify<Set<Output<ValueShape>> | DefaultValue>

    The value that conforms the output type of the shape.

Plugin Methods

  • Constrains the maximum set size.

    Parameters

    • size: number

      The maximum set size.

    • Optionaloptions: IssueOptions | Message

      The issue options or the issue message.

    Returns this

    The clone of the shape.

  • Constrains the minimum set size.

    Parameters

    • size: number

      The minimum set size.

    • Optionaloptions: IssueOptions | Message

      The issue options or the issue message.

    Returns this

    The clone of the shape.

  • Constrains the Set to contain at least one element.

    Parameters

    Returns this

    The clone of the shape.

  • Constrains the set size.

    Parameters

    • size: number

      The minimum set size.

    • Optionaloptions: IssueOptions | Message

      The issue options or the issue message.

    Returns this

    The clone of the shape.