Function hasFieldOfType

  • Checks that obj is an object, and it has a field named fieldName and that its type is fieldType
    Assuming e is an object with the field code of type string.

    • If you use this, then the expression following it is valid, for example:
      • hasFieldOfType(e, "code", "string") && e.code === "INSUFFICIENT_FUNDS")
    • If you do not use it, then
      • e.code is invalid when checked by code analyzer

    Type Parameters

    • T

    Parameters

    • obj: unknown
    • fieldName: string
    • fieldType: string

    Returns obj is {
        [fieldName: string]: T;
    }