Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MismatchInfo

Represents the result of running mismatch(suspect, typeDescr) or duckMismatch(suspect, typeDescr) functions.

remarks

It contains information about why suspect doesn't conform to the given typeDescr: the actual value, expected type description and a property path to unexpected value type.

Hierarchy

Implements

Index

Constructors

constructor

  • Creates an instance of MismatchInfo, takes on object with data properties. You will never used it, it is used only internally.

    Parameters

    • mismatchData: MismatchInfoData

      Object which contains data about type mismatch.

    Returns MismatchInfo

Properties

actualValue

actualValue: unknown

Value that failed to conform to the expectedTd.

expectedTd

expectedTd: TypeDescription

TypeDescription that actualValue was expected to conform to.

path

path: PathArray

An array of numbers and strings which defines a path to suspect's invalid actualValue. @remarks E.g. if suspect.foo.bar[3][5] failed to match to the expectedTd, then path would be [ 'foo', 'bar', 3, 5 ].

Methods

pathString

  • pathString(): string | number
  • Returns path converted to a human readable JavaScript property access notation string if match was failed. Returned string begins with the 'root' as the root object to access the properties.

    remarks
    import * as Vts from 'vee-type-safe';
    const mismatchInfo = Vts.mismatch(
        {
            foo: {
                bar: {
                    'twenty two': [
                        { prop: 'str' },
                        { prop: -23 }
                    ]
                }
            }
        },
        { foo: { bar: { 'twenty two': [ { prop: 'string' } ] } } }
    );
    
    mismatchInfo.pathString() === `root.foo.bar['twenty two'][1].prop`;

    Returns string | number

toErrorString

  • toErrorString(): string
  • Returns a string of form: "value (JSON.stringify(actualValue)) at path 'pathString()' doesn't exactly conform to the given type description (stringifyTd(expectedTd))"

    remarks

    If JSON.stringify(actualValue) throws an error, it is excluded from the returned string.

    Returns string

Generated using TypeDoc