Function asConst

  • Takes a constant value and produces a decoder that can only decode that value.

    example:

    const d1: ConstDecoder<2> = asConst(2)
    const d2: ConstDecoder<"accepted"> = asConst("accepted")
    const d3: ConstDecoder<true> = asConst(true)

    This can also be used for singleton objects, i.e. to check that you have the same instance of an object.

    here's an example of using this to ensure you recieve the same instance of a database configuration.

    // the instance you want to recieve
    const dbInstance = new DB({ url: configURL, pass: password })
    const asDBInstance = asConst(dbInstance)

    const anotherInstance = new DB({ url: configURL, pass: password })
    asDBInstance.decode(anotherInstance)
    //> fails because anotherInstance is not dbInstance

    Type Parameters

    • L

    Parameters

    Returns ConstDecoder<L>

    decoder for constant value

Generated using TypeDoc