Type alias GetField<Obj, Key, Default>

GetField<Obj, Key, Default>: Key extends keyof Obj
    ? Obj[Key]
    : Default

Dynamically get the field type, even if Key is not a key of Obj.

Type Parameters

  • Obj extends object

    the object type to query.

  • Key

    the key to query. Key is not forced to be keyof Obj.

  • Default = never

    the type to return if in reality, Key is not keyof Obj.

Remarks

Sometimes, when defining a new type, tsc could not infer the initial type of Obj or Key. For example, ContractMethodNames for the plain Contract is forced to be never. This type is used to bypass the initial typing, and get the actual type when it is used.

Returns

Obj[key] if Key is keyof Obj. Otherwise Default is returned.

Generated using TypeDoc