Skip to main content

Built and signed on GitHub Actions

🏷️ Collection of TypeScript types.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 weeks ago (0.3.3)
type alias ArrayLikeIndexFallback

Gets the possible index values of a ReadonlyArrayLike, and fallbacks to number when it can't be inferred.

Examples

Example 1

const triple = ["🧙‍♀️", "🔮", "💀"] as const;
const array = ["🧙‍♀️", "🔮", "💀"];

type IndexOfTriple = ArrayLikeIndexFallback<typeof triple>; // 0 | 1 | 2
type IndexOfArray = ArrayLikeIndexFallback<typeof array>; // number

Type Parameters

Array extends Pick<ReadonlyArrayLike, "length">

An array-like (we mainly care about it having a length).

Definition

NeverFallback<Just<Exclude<Partial<Array>["length"], Array["length"]>>, number>

See

Add Package

deno add jsr:@coven/types

Import symbol

import { type ArrayLikeIndexFallback } from "@coven/types";

---- OR ----

Import directly with a jsr specifier

import { type ArrayLikeIndexFallback } from "jsr:@coven/types";

Add Package

npx jsr add @coven/types

Import symbol

import { type ArrayLikeIndexFallback } from "@coven/types";

Add Package

yarn dlx jsr add @coven/types

Import symbol

import { type ArrayLikeIndexFallback } from "@coven/types";

Add Package

pnpm dlx jsr add @coven/types

Import symbol

import { type ArrayLikeIndexFallback } from "@coven/types";

Add Package

bunx jsr add @coven/types

Import symbol

import { type ArrayLikeIndexFallback } from "@coven/types";