Type Alias IndexAt<A, N, Fail, Upper, Lower>

IndexAt<A, N, Fail, Upper, Lower>: IsNever<A, $SelectionBranch> extends infer R
    ? R extends $Then
        ? Fail
        : R extends $Else
            ? ArrayPlus.IndexAt._<A, N, Fail, Upper, Lower>
            : never
    : never

🦴 utilities

Gets the normalized index to access the element of an array or tuple.

Type Parameters

  • A extends readonly unknown[]
  • N extends number
  • Fail = never
  • Upper = A["length"]
  • Lower = 0
type R = IndexAt<['a', 'b', 'c'], 2> // 2
type R = IndexAt<['a', 'b', 'c'], -2> // 1

type R = IndexAt<['a', 'b', 'c'], 3> // never
type R = IndexAt<['a', 'b', 'c'], -4> // never