devtypes - v2.0.0
    Preparing search index...

    Type Alias Coerce<T, U>

    Coerce: T extends U ? T : U

    Coerce a type while preserving assignability.

    Type Parameters

    • T

      Source type

    • U

      Target type

    Keeps the source type if it is assignable to the target type; otherwise, resolves to the target type.

    type A = Coerce< string, string | number >;   // string
    type B = Coerce< number, string | number >; // number
    type C = Coerce< boolean, string | number >; // string | number