Skip to content

IndexOf

Since 1.4.0

Gets the index of a specific element type in a tuple. This is an alias for FindIndex. Returns -1 if not found.

Signature

typescript
export type IndexOf<T extends unknown[], U> = FindIndex<T, U>

Parameters

ParameterDescription
TThe tuple to search through
UThe type to find the index of

Examples

Basic Usage

typescript
import type { IndexOf } from 'uni-types'

type Index = IndexOf<['a', 'b', 'c', 'b'], 'b'> // 1

Element Not Found

typescript
import type { IndexOf } from 'uni-types'

type Index = IndexOf<['a', 'b', 'c'], 'd'> // -1
  • FindIndex - Find index of first matching element
  • Find - Find first matching element
  • Includes - Check if tuple includes element

Released under the MIT License.