Defines a method that a type implements to compare two objects.

interface IComparer<T> {
    constructor: any;
    Cast<T1, T2>(this: T2, type: TypeRef<T1>): T1;
    Compare(x: T | JsType<T>, y: T | JsType<T>): number;
    TryCast<T1, T2>(this: T2, type: TypeRef<T1>): null | T1;
}

Type Parameters

  • T

Hierarchy (view full)

Constructors

Methods

Constructors

constructor

Methods

  • Casts this object to the specified type. Throws error on failure.

    Type Parameters

    • T1

      The target type of the cast.

    • T2

      The type of the object to cast.

    Parameters

    Returns T1

  • Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.

    Parameters

    • x: T | JsType<T>

      The first object to compare.

    • y: T | JsType<T>

      The second object to compare.

    Returns number

    A signed integer that indicates the relative values of x and y, as shown in the following table. Value

    Meaning

    Less than zero

    x is less than y.

    Zero

    x equals y.

    Greater than zero

    x is greater than y.

  • Casts this object to the specified type. Returns null on failure.

    Type Parameters

    • T1

      The target type of the cast.

    • T2

      The type of the object to cast.

    Parameters

    Returns null | T1