The InvalidTypeError is thrown when a value associated with a key is not of the expected type.

This error helps enforce type safety in parsers by signaling when the actual type of a value differs from the expected type.

throw new Parser.InvalidTypeError("age", "number", typeof value);
// Error: Key "age" expected number but got string

Hierarchy (View Summary)

Constructors

  • Constructs a new InvalidTypeError with the specified key, expected type, and actual type.

    Parameters

    • key: string

      The name of the key with the invalid type.

    • expected: string

      The expected type of the value.

    • actual: string

      The actual type of the value.

    Returns InvalidTypeError

Properties

cause?: unknown
message: string
name: string = "ParserInvalidTypeError"
stack?: string
prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

stackTraceLimit: number

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void