Interface NotShape<BaseShape, ExcludedShape>

Shortcut for ExcludeShape that doesn't impose the exclusion on the type level.

interface NotShape<BaseShape, ExcludedShape> {
    _applyOperations: ApplyOperationsCallback;
    annotations: Dict<any>;
    baseShape: BaseShape;
    excludedShape: ExcludedShape;
    inputs: readonly unknown[];
    isAsync: boolean;
    operations: readonly Operation[];
    _apply(input, options, _nonce): Result<Output<BaseShape>>;
    _applyAsync(input, options, nonce): Promise<Result<Output<BaseShape>>>;
    _clone(): this;
    _getInputs(): readonly unknown[];
    _isAsync(): boolean;
    accepts(input): boolean;
    addAsyncOperation<Param>(cb, options?): this;
    addAsyncOperation(cb, options?): this;
    addOperation<Param>(cb, options?): this;
    addOperation(cb, options?): this;
    allow<AllowedValue>(value): AllowShape<NotShape<BaseShape, ExcludedShape>, AllowedValue>;
    alter<Param>(cb, options): this;
    alter(cb, options?): this;
    alterAsync<Param>(cb, options): this;
    alterAsync(cb, options?): this;
    annotate(annotations): this;
    at(_key): null | AnyShape;
    brand<Brand>(): RefineShape<NotShape<BaseShape, ExcludedShape>, Branded<Output<BaseShape>, Brand>>;
    catch(): CatchShape<NotShape<BaseShape, ExcludedShape>, undefined>;
    catch<FallbackValue>(fallback): CatchShape<NotShape<BaseShape, ExcludedShape>, FallbackValue>;
    check<Param>(cb, options): this;
    check(cb, options?): this;
    checkAsync<Param>(cb, options): this;
    checkAsync(cb, options?): this;
    convert<ConvertedValue>(cb): Shape<Input<BaseShape>, ConvertedValue>;
    convertAsync<ConvertedValue>(cb): Shape<Input<BaseShape>, ConvertedValue>;
    deepPartial(): NotShape<DeepPartialShape<BaseShape>, ExcludedShape>;
    deny<DeniedValue>(value, options?): DenyShape<NotShape<BaseShape, ExcludedShape>, DeniedValue>;
    exclude<ExcludedShape>(shape, options?): ExcludeShape<NotShape<BaseShape, ExcludedShape>, ExcludedShape>;
    nonOptional(options?): DenyShape<NotShape<BaseShape, ExcludedShape>, undefined>;
    not<ExcludedShape>(shape, options?): NotShape<NotShape<BaseShape, ExcludedShape>, ExcludedShape>;
    nullable(): AllowShape<NotShape<BaseShape, ExcludedShape>, null>;
    nullable<DefaultValue>(defaultValue): ReplaceShape<NotShape<BaseShape, ExcludedShape>, null, DefaultValue>;
    nullish(): AllowShape<AllowShape<NotShape<BaseShape, ExcludedShape>, null>, undefined>;
    nullish<DefaultValue>(defaultValue?): ReplaceShape<ReplaceShape<NotShape<BaseShape, ExcludedShape>, null, DefaultValue>, undefined, DefaultValue>;
    optional(): AllowShape<NotShape<BaseShape, ExcludedShape>, undefined>;
    optional<DefaultValue>(defaultValue): ReplaceShape<NotShape<BaseShape, ExcludedShape>, undefined, DefaultValue>;
    parse(input, options?): Output<BaseShape>;
    parseAsync(input, options?): Promisify<Output<BaseShape>>;
    parseOrDefault(input): undefined | Output<BaseShape>;
    parseOrDefault<DefaultValue>(input, defaultValue, options?): Output<BaseShape> | DefaultValue;
    parseOrDefaultAsync(input): Promisify<undefined | Output<BaseShape>>;
    parseOrDefaultAsync<DefaultValue>(input, defaultValue, options?): Promisify<Output<BaseShape> | DefaultValue>;
    refine<RefinedValue, Param>(cb, options): RefineShape<NotShape<BaseShape, ExcludedShape>, RefinedValue>;
    refine<RefinedValue>(cb, options?): RefineShape<NotShape<BaseShape, ExcludedShape>, RefinedValue>;
    refine<Param>(cb, options?): this;
    refine(cb, options?): this;
    refineAsync<Param>(cb, options?): this;
    refineAsync(cb, options?): this;
    replace<InputValue, OutputValue>(inputValue, outputValue): ReplaceShape<NotShape<BaseShape, ExcludedShape>, InputValue, OutputValue>;
    to<OutputShape>(shape): PipeShape<NotShape<BaseShape, ExcludedShape>, OutputShape>;
    try(input, options?): Err | Ok<Output<BaseShape>>;
    tryAsync(input, options?): Promise<Err | Ok<Output<BaseShape>>>;
}

Type Parameters

  • BaseShape extends AnyShape

    The base shape.

  • ExcludedShape extends AnyShape

    The shape to which the output must not conform.

Hierarchy (view full)

Properties

_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.

annotations: Dict<any> = {}

The dictionary of shape annotations.

baseShape: BaseShape

The base shape.

excludedShape: ExcludedShape

The shape to which the output must not conform.

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.

operations: readonly Operation[] = []

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

Methods

  • Synchronously parses the input.

    Parameters

    • input: unknown

      The shape input to parse.

    • options: ParseOptions

      Parsing options.

    • _nonce: number

      The globally unique number that identifies the parsing process.

    Returns Result<Output<BaseShape>>

    null if input matches the output, Ok that wraps the output, or an array of captured issues.

  • Asynchronously parses the input.

    Parameters

    • input: unknown

      The shape input to parse.

    • options: ParseOptions

      Parsing options.

    • nonce: number

      The globally unique number that identifies the parsing process.

    Returns Promise<Result<Output<BaseShape>>>

    null if input matches the output, Ok that wraps the output, or an array of captured issues.

  • 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

      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.

  • Asynchronously parses the value.

    Parameters

    • input: unknown

      The value to parse.

    • Optional options: ParseOptions

      Parsing options.

    Returns Promisify<Output<BaseShape>>

    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.

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

    Parameters

    • input: unknown

      The value to parse.

    Returns undefined | Output<BaseShape>

    The value that conforms the output type of the shape.

    Throws

    Error if the shape doesn't support the sync parsing, see Shape.isAsync.

  • Synchronously 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.

    • Optional options: ParseOptions

      Parsing options.

    Returns Output<BaseShape> | DefaultValue

    The value that conforms the output type of the shape.

    Throws

    Error if the shape doesn't support the sync parsing, see Shape.isAsync.

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

    Parameters

    • input: unknown

      The value to parse.

    Returns Promisify<undefined | Output<BaseShape>>

    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.

    • Optional options: ParseOptions

      Parsing options.

    Returns Promisify<Output<BaseShape> | DefaultValue>

    The value that conforms the output type of the shape.

  • Asynchronously parses the value and returns Ok or Err object that wraps the result.

    Parameters

    • input: unknown

      The value to parse.

    • Optional options: ParseOptions

      Parsing options.

    Returns Promise<Err | Ok<Output<BaseShape>>>

    The Ok instance if parsing has succeeded or Err if parsing has failed.