#100·ts-reset

Array `.at()` on readonly tuples

Author: SheraffCreated Mar 6, 2023Updated Apr 1, 2026
Labelsenhancementneeds-triage

Unless there is a good reason for typescript not to return the correct type when accessing a tuple with .at it feels like a good candidate for this library.

This is how it is currently:

typescript
const a = [false, 1, '2'] as const

const b = a.at(0)
//    ^? const b: false | 1 | "2" | undefined

const c = a.at(-1)
//    ^? const c: false | 1 | "2" | undefined

But with this library it could be:

typescript
const a = [false, 1, '2'] as const

const b = a.at(0)
//    ^? const b: false

const c = a.at(-1)
//    ^? const c: "2"