Class MapShape<KeyShape, ValueShape>

The shape of a Map instance.

Type Parameters

  • KeyShape extends AnyShape

    The key shape.

  • ValueShape extends AnyShape

    The value shape.

Hierarchy (view full)

Implements

Constructors

Properties

_applyCoerce: ((input) => [unknown, unknown][]) = coerceToNever

Applies coercion rules to the given value. Call this method in Shape._apply and Shape._applyAsync to coerce the input.

Override CoercibleShape._coerce and Shape._getInputs methods to implement custom type coercion.

Type declaration

    • (input): [unknown, unknown][]
    • Parameters

      • input: unknown

        The input value to coerce.

      Returns [unknown, unknown][]

Returns

The coerced value, or NEVER if coercion isn't possible.

_applyOperations: ApplyOperationsCallback

The callback that applies Shape.operations to the shape output value.

This method returns a promise if there are async Shape.operations.

If the shape overrides only Shape._apply and doesn't override Shape._applyAsync then it's only safe to call this method as the last statement in Shape._apply. Otherwise, it may return an unexpected promise.

If the shape overrides both Shape._apply and Shape._applyAsync then this method would always synchronously return a Result inside Shape._apply.

_options: undefined | IssueOptions | Message

The issue options or the issue message.

_typeIssueFactory: ((input, options) => Issue)

Returns issues associated with an invalid input value type.

Type declaration

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.

keyShape: KeyShape

The key shape.

operations: readonly Operation[] = []

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

valueShape: ValueShape

The value shape.

messages: Messages = defaultMessages

The mapping from an issue type to a corresponding issue message.

Methods

  • Coerces a value to an array of Map entries.

    Parameters

    • input: unknown

      A value to coerce.

    Returns [unknown, unknown][]

    An array of entries, or NEVER if coercion isn't possible.

  • 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

      The key for which the sub-shape must be retrieved.

    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.

Accessors

  • get isCoercing(): boolean
  • true if this shapes coerces input values to the required type during parsing, or false otherwise.

    Returns boolean