Type Alias FindLast<A, Criteria>

FindLast<A, Criteria>: IsTuple<A, {
    $else: A extends Readonly<(infer T)[]>
        ? T extends Criteria
            ? T | undefined
            : never
        : never;
    $then: A["length"] extends 0
        ? never
        : A extends readonly [...(infer Heads), infer Last]
            ? Last extends Criteria
                ? Last
                : FindLast<Heads, Criteria>
            : never;
}>

🦴 utilities

Gets the last type in the array or tuple that matches the Criteria.

If the Criteria is not met, it will return `never'.

For Array<T>, it will return T | undefined if T satisfies Criteria.

Type Parameters

  • A extends readonly unknown[]
  • Criteria
ArrayPlus.Find<Array<1 | 2 | 'x'>, number> // 1 | 2 | undefined

ArrayPlus.Find<[true, 123, 'x', 321], number> // 321