@alanscodelog/utils
    Preparing search index...

    Type Alias ExtractByValue<TObj, TValType>

    ExtractByValue: { [K in keyof TObj]: TObj[K] extends TValType ? K : never }[keyof TObj]

    Like extract, but extracts the keys of an object by the type of the value.

    This is useful, for example, when we have a function that can only handle x type of values but is passed a key to access that type. For example:

    type Example = {
    a: string
    b: number
    c: boolean
    }
    type ExampleStrings = ExtractByValue<Example, string> // "a"

    const extractStrings = <T>(val: T, key: ExtractByValue<T, string[]>) => val[key].sort(...).map(...)

    Type Parameters

    • TObj
    • TValType