or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

any.mdboolean.mdclass.mdcommunity.mdfunction.mdindex.mditeration.mdlist.mdmisc.mdnumber.mdobject.mdstring.mdtesting.mdunion.md

list.mddocs/

0

# List Module

1

2

Comprehensive array and tuple manipulation utilities - the largest module with 73+ operations for transforming, accessing, and modifying list types.

3

4

## Capabilities

5

6

### Core Manipulation

7

8

Essential operations for adding, removing, and rearranging list elements.

9

10

```typescript { .api }

11

/**

12

* Add element to the end of list

13

* @param L - List to append to

14

* @param A - Element to append

15

* @returns New list with element appended

16

*/

17

type Append<L extends List, A> = [...L, A];

18

19

/**

20

* Add element to the beginning of list

21

* @param L - List to prepend to

22

* @param A - Element to prepend

23

* @returns New list with element prepended

24

*/

25

type Prepend<L extends List, A> = [A, ...L];

26

27

/**

28

* Concatenate two lists

29

* @param L1 - First list

30

* @param L2 - Second list

31

* @returns Combined list

32

*/

33

type Concat<L1 extends List, L2 extends List> = [...L1, ...L2];

34

35

/**

36

* Reverse the order of elements in list

37

* @param L - List to reverse

38

* @returns List with elements in reverse order

39

*/

40

type Reverse<L extends List> = ReverseImpl<L>;

41

42

/**

43

* Remove last element from list

44

* @param L - List to pop from

45

* @returns List without last element

46

*/

47

type Pop<L extends List> = L extends readonly [...infer Rest, any] ? Rest : [];

48

49

/**

50

* Remove first N elements from list

51

* @param L - List to drop from

52

* @param N - Number of elements to drop

53

* @returns List without first N elements

54

*/

55

type Drop<L extends List, N extends number> = DropImpl<L, N>;

56

57

/**

58

* Take first N elements from list

59

* @param L - List to take from

60

* @param N - Number of elements to take

61

* @returns List with only first N elements

62

*/

63

type Take<L extends List, N extends number> = TakeImpl<L, N>;

64

```

65

66

**Usage Examples:**

67

68

```typescript

69

import { L } from "ts-toolbelt";

70

71

type Numbers = [1, 2, 3];

72

type Letters = ["a", "b"];

73

74

type WithFour = L.Append<Numbers, 4>; // [1, 2, 3, 4]

75

type WithZero = L.Prepend<Numbers, 0>; // [0, 1, 2, 3]

76

type Combined = L.Concat<Numbers, Letters>; // [1, 2, 3, "a", "b"]

77

type Reversed = L.Reverse<Numbers>; // [3, 2, 1]

78

type Popped = L.Pop<Numbers>; // [1, 2]

79

type DropTwo = L.Drop<[1, 2, 3, 4, 5], 2>; // [3, 4, 5]

80

type TakeTwo = L.Take<[1, 2, 3, 4, 5], 2>; // [1, 2]

81

```

82

83

### Access Operations

84

85

Get specific elements and information from lists.

86

87

```typescript { .api }

88

/**

89

* Get element at specific index

90

* @param L - List to access

91

* @param K - Index to access

92

* @returns Element at index K

93

*/

94

type At<L extends List, K extends number> = L[K];

95

96

/**

97

* Get first element of list

98

* @param L - List to get head from

99

* @returns First element or never if empty

100

*/

101

type Head<L extends List> = L extends readonly [infer H, ...any[]] ? H : never;

102

103

/**

104

* Get all elements except first

105

* @param L - List to get tail from

106

* @returns List without first element

107

*/

108

type Tail<L extends List> = L extends readonly [any, ...infer T] ? T : [];

109

110

/**

111

* Get last element of list

112

* @param L - List to get last from

113

* @returns Last element or never if empty

114

*/

115

type Last<L extends List> = L extends readonly [...any[], infer L] ? L : never;

116

117

/**

118

* Get length of list

119

* @param L - List to measure

120

* @returns Length as number literal

121

*/

122

type Length<L extends List> = L['length'];

123

124

/**

125

* Extract valid keys (indices) from list

126

* @param L - List to extract keys from

127

* @returns Union of valid indices

128

*/

129

type Keys<L extends List> = Exclude<keyof L, keyof []>;

130

131

/**

132

* Extract known keys (non-index signature) from list

133

* @param L - List to extract known keys from

134

* @returns Union of known indices

135

*/

136

type KnownKeys<L extends List> = KnownKeysImpl<L>;

137

```

138

139

**Usage Examples:**

140

141

```typescript

142

import { L } from "ts-toolbelt";

143

144

type Items = ["apple", "banana", "cherry"];

145

146

type Second = L.At<Items, 1>; // "banana"

147

type First = L.Head<Items>; // "apple"

148

type Rest = L.Tail<Items>; // ["banana", "cherry"]

149

type Last = L.Last<Items>; // "cherry"

150

type Count = L.Length<Items>; // 3

151

type Indices = L.Keys<Items>; // 0 | 1 | 2

152

type KnownIndices = L.KnownKeys<Items>; // 0 | 1 | 2

153

154

// With mixed tuple

155

type Mixed = [string, number, ...boolean[]];

156

type MixedKeys = L.Keys<Mixed>; // number (includes index signature)

157

type MixedKnown = L.KnownKeys<Mixed>; // 0 | 1

158

```

159

160

### Query Operations

161

162

Check membership, inclusion, and constraints on lists.

163

164

```typescript { .api }

165

/**

166

* Check if list contains specific element

167

* @param L - List to check

168

* @param A - Element to look for

169

* @returns 1 if element is found, 0 otherwise

170

*/

171

type Has<L extends List, A> = A extends L[number] ? 1 : 0;

172

173

/**

174

* Check if list includes element (alias for Has)

175

* @param L - List to check

176

* @param A - Element to look for

177

* @returns 1 if element is included, 0 otherwise

178

*/

179

type Includes<L extends List, A> = Has<L, A>;

180

181

/**

182

* Ensure list has at least N elements

183

* @param L - List to check

184

* @param N - Minimum number

185

* @returns List type with at least N elements constraint

186

*/

187

type AtLeast<L extends List, N extends number> = AtLeastImpl<L, N>;

188

```

189

190

**Usage Examples:**

191

192

```typescript

193

import { L } from "ts-toolbelt";

194

195

type Fruits = ["apple", "banana", "cherry"];

196

197

type HasApple = L.Has<Fruits, "apple">; // 1

198

type HasOrange = L.Has<Fruits, "orange">; // 0

199

type IncludesBanana = L.Includes<Fruits, "banana">; // 1

200

201

// AtLeast constraint

202

type AtLeastTwo = L.AtLeast<[string, number], 2>; // [string, number]

203

type AtLeastFive = L.AtLeast<[string], 5>; // Constraint ensures minimum 5 elements

204

```

205

206

### Transformation Operations

207

208

Transform lists using mapping, filtering, and grouping operations.

209

210

```typescript { .api }

211

/**

212

* Filter list elements based on condition

213

* @param L - List to filter

214

* @param M - Condition to filter by

215

* @returns List with elements matching condition

216

*/

217

type Filter<L extends List, M> = FilterImpl<L, M>;

218

219

/**

220

* Group list elements by criteria

221

* @param L - List to group

222

* @param K - Grouping criteria

223

* @returns Grouped structure

224

*/

225

type Group<L extends List, K> = GroupImpl<L, K>;

226

227

/**

228

* Flatten nested lists

229

* @param L - List to flatten

230

* @param depth - Flatten depth

231

* @returns Flattened list

232

*/

233

type Flatten<L extends List, depth extends number = 1> = FlattenImpl<L, depth>;

234

235

/**

236

* Zip two lists together

237

* @param L1 - First list

238

* @param L2 - Second list

239

* @returns List of paired elements

240

*/

241

type Zip<L1 extends List, L2 extends List> = ZipImpl<L1, L2>;

242

243

/**

244

* Create object from list of keys and list of values

245

* @param K - List of keys

246

* @param V - List of values

247

* @returns Object with zipped key-value pairs

248

*/

249

type ZipObj<K extends readonly (string | number | symbol)[], V extends List> = ZipObjImpl<K, V>;

250

251

/**

252

* Convert list to object with indices as keys

253

* @param L - List to convert

254

* @returns Object representation of list

255

*/

256

type ObjectOf<L extends List> = { [K in keyof L]: L[K] };

257

258

/**

259

* Convert object to list of values

260

* @param O - Object to convert

261

* @returns List of object values

262

*/

263

type ListOf<O extends Record<number, any>> = ListOfImpl<O>;

264

```

265

266

**Usage Examples:**

267

268

```typescript

269

import { L } from "ts-toolbelt";

270

271

type Numbers = [1, 2, 3, 4, 5];

272

type Mixed = [string, number, boolean];

273

274

// Filter even numbers (conceptual - actual implementation varies)

275

type EvenNumbers = L.Filter<Numbers, 2 | 4>; // [2, 4]

276

277

// Zip lists

278

type List1 = ["a", "b", "c"];

279

type List2 = [1, 2, 3];

280

type Zipped = L.Zip<List1, List2>; // [["a", 1], ["b", 2], ["c", 3]]

281

282

// Zip to object

283

type Keys = ["name", "age", "active"];

284

type Values = [string, number, boolean];

285

type UserSchema = L.ZipObj<Keys, Values>; // { name: string; age: number; active: boolean }

286

287

// List to object conversion

288

type ListAsObj = L.ObjectOf<["a", "b", "c"]>; // { 0: "a"; 1: "b"; 2: "c" }

289

290

// Object to list conversion

291

type ObjAsList = L.ListOf<{ 0: "a"; 1: "b"; 2: "c" }>; // ["a", "b", "c"]

292

293

// Flatten nested arrays

294

type Nested = [[1, 2], [3, [4, 5]]];

295

type FlatOnce = L.Flatten<Nested>; // [1, 2, 3, [4, 5]]

296

type FlatDeep = L.Flatten<Nested, 2>; // [1, 2, 3, 4, 5]

297

```

298

299

### Set Operations

300

301

Operations treating lists as sets for intersection, difference, and exclusion.

302

303

```typescript { .api }

304

/**

305

* Set difference - elements in L1 but not in L2

306

* @param L1 - First list

307

* @param L2 - Second list

308

* @returns Elements unique to first list

309

*/

310

type Diff<L1 extends List, L2 extends List> = DiffImpl<L1, L2>;

311

312

/**

313

* Set intersection - elements common to both lists

314

* @param L1 - First list

315

* @param L2 - Second list

316

* @returns Common elements

317

*/

318

type Intersect<L1 extends List, L2 extends List> = IntersectImpl<L1, L2>;

319

320

/**

321

* Exclude specific elements from list

322

* @param L - List to exclude from

323

* @param A - Elements to exclude

324

* @returns List without excluded elements

325

*/

326

type Exclude<L extends List, A> = ExcludeImpl<L, A>;

327

328

/**

329

* Extract specific elements from list

330

* @param L - List to extract from

331

* @param A - Elements to extract

332

* @returns List with only extracted elements

333

*/

334

type Extract<L extends List, A> = ExtractImpl<L, A>;

335

336

/**

337

* Remove duplicate elements from list

338

* @param L - List to deduplicate

339

* @returns List with unique elements only

340

*/

341

type Unique<L extends List> = UniqueImpl<L>;

342

```

343

344

**Usage Examples:**

345

346

```typescript

347

import { L } from "ts-toolbelt";

348

349

type List1 = [1, 2, 3, 4];

350

type List2 = [3, 4, 5, 6];

351

352

type Difference = L.Diff<List1, List2>; // [1, 2]

353

type Common = L.Intersect<List1, List2>; // [3, 4]

354

type WithoutNumbers = L.Exclude<[1, "a", 2, "b"], number>; // ["a", "b"]

355

type OnlyNumbers = L.Extract<[1, "a", 2, "b"], number>; // [1, 2]

356

357

type WithDuplicates = [1, 2, 2, 3, 3, 3];

358

type UniqueOnly = L.Unique<WithDuplicates>; // [1, 2, 3]

359

```

360

361

### Key Operations

362

363

Operations for working with list keys, indices, and key-based filtering.

364

365

```typescript { .api }

366

/**

367

* Get the keys of L which entries match M

368

* @param L - List to extract from

369

* @param M - Type to select entries

370

* @param match - Precision mode for matching

371

* @returns Union of keys whose values match M

372

*/

373

type SelectKeys<L extends List, M extends any, match extends Match = 'default'> = SelectKeysImpl<L, M, match>;

374

375

/**

376

* Filter out the keys of L which entries match M

377

* @param L - List to remove from

378

* @param M - Type to select entries

379

* @param match - Precision mode for matching

380

* @returns Union of keys whose values don't match M

381

*/

382

type FilterKeys<L extends List, M extends any, match extends Match = 'default'> = FilterKeysImpl<L, M, match>;

383

384

/**

385

* Get the intersecting keys of L & L1

386

* @param L - List to check similarities with

387

* @param L1 - List to check similarities against

388

* @param match - Precision mode for matching

389

* @returns Union of common keys

390

*/

391

type IntersectKeys<L extends List, L1 extends List, match extends Match = 'default'> = IntersectKeysImpl<L, L1, match>;

392

393

/**

394

* Create a set of keys from range

395

* @param From - Starting index

396

* @param To - Ending index

397

* @returns Union of keys in range

398

*/

399

type KeySet<From extends number, To extends number> = KeySetImpl<From, To>;

400

401

/**

402

* Get the last index of L

403

* @param L - List to get last index from

404

* @returns Last valid index number

405

*/

406

type LastKey<L extends List> = Length<Tail<L>>;

407

```

408

409

### Key Classifications

410

411

Operations for categorizing keys by their type characteristics.

412

413

```typescript { .api }

414

/**

415

* Get the keys of L that are optional

416

* @param L - List to extract from

417

* @returns Union of optional keys

418

*/

419

type OptionalKeys<L extends List> = OptionalKeysImpl<L>;

420

421

/**

422

* Get the keys of L that are required

423

* @param L - List to extract from

424

* @returns Union of required keys

425

*/

426

type RequiredKeys<L extends List> = RequiredKeysImpl<L>;

427

428

/**

429

* Get the keys of L that are readonly

430

* @param L - List to extract from

431

* @returns Union of readonly keys

432

*/

433

type ReadonlyKeys<L extends List> = ReadonlyKeysImpl<L>;

434

435

/**

436

* Get the keys of L that are writable

437

* @param L - List to extract from

438

* @returns Union of writable keys

439

*/

440

type WritableKeys<L extends List> = WritableKeysImpl<L>;

441

442

/**

443

* Get the keys of L that are nullable

444

* @param L - List to extract from

445

* @returns Union of nullable keys

446

*/

447

type NullableKeys<L extends List> = NullableKeysImpl<L>;

448

449

/**

450

* Get the keys of L that are non-nullable

451

* @param L - List to extract from

452

* @returns Union of non-nullable keys

453

*/

454

type NonNullableKeys<L extends List> = NonNullableKeysImpl<L>;

455

456

/**

457

* Get the keys of L that are undefinable

458

* @param L - List to extract from

459

* @returns Union of undefinable keys

460

*/

461

type UndefinableKeys<L extends List> = UndefinableKeysImpl<L>;

462

```

463

464

### Path Operations

465

466

Operations for navigating and accessing nested properties in lists.

467

468

```typescript { .api }

469

/**

470

* Get the type at nested path in L

471

* @param L - List to be inspected

472

* @param Path - Path to be followed

473

* @returns Type at the specified path

474

*/

475

type Path<L extends List, Path extends List<Key>> = PathImpl<L, Path>;

476

477

/**

478

* Get all possible paths of L

479

* @param L - List to be inspected

480

* @returns Union of all possible paths

481

*/

482

type Paths<L extends List> = PathsImpl<L>;

483

484

/**

485

* Check whether L has nested entries that match M

486

* @param L - List to be inspected

487

* @param Path - Path to be followed

488

* @param M - Type to check entry type

489

* @param match - Precision mode for matching

490

* @returns 1 if path exists and matches, 0 otherwise

491

*/

492

type HasPath<L extends List, Path extends List<Key>, M extends any = any, match extends Match = 'default'> = HasPathImpl<L, Path, M, match>;

493

```

494

495

### Range Operations

496

497

Operations for extracting and removing ranges of elements.

498

499

```typescript { .api }

500

/**

501

* Pick a range of entries from L

502

* @param L - List to pick from

503

* @param From - Starting index

504

* @param To - Ending index

505

* @returns List containing elements in range

506

*/

507

type Extract<L extends List, From extends number, To extends number> = Pick<L, KeySet<From, To>>;

508

509

/**

510

* Remove a range of entries from L

511

* @param L - List to remove from

512

* @param From - Starting index

513

* @param To - Ending index

514

* @returns List without elements in range

515

*/

516

type Remove<L extends List, From extends number, To extends number> = Omit<L, KeySet<From, To>>;

517

```

518

519

### List Modification Operations

520

521

Advanced operations for modifying, patching, and updating list elements.

522

523

```typescript { .api }

524

/**

525

* Assign a list of Lists into L with Merge

526

* @param L - List to assign to

527

* @param Ls - Lists to assign

528

* @param depth - Merge depth ('flat' or 'deep')

529

* @param ignore - Types not to merge

530

* @param fill - Types to be replaced

531

* @returns Modified list

532

*/

533

type Assign<L extends List, Ls extends List<List>, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = Cast<OAssign<L, Ls, depth, ignore, fill>, List>;

534

535

/**

536

* Update the entries of L with the ones of L1

537

* @param L - List to update

538

* @param L1 - List to update with

539

* @returns Updated list

540

*/

541

type Overwrite<L extends List, L1 extends object> = OverwriteImpl<L, L1>;

542

543

/**

544

* Modify L with LMod using placeholder substitution

545

* @param L - List to copy from

546

* @param LMod - Modification template

547

* @returns Modified list

548

*/

549

type Modify<L extends List, LMod extends List> = ModifyImpl<L, LMod>;

550

551

/**

552

* Complete the fields of L with the ones of L1

553

* @param L - List to complete

554

* @param L1 - List to copy from

555

* @param depth - Patch depth ('flat' or 'deep')

556

* @param ignore - Types not to merge

557

* @param fill - Types to be replaced

558

* @returns Patched list

559

*/

560

type Patch<L extends List, L1 extends List, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = PatchImpl<L, L1, depth, ignore, fill>;

561

562

/**

563

* Patch a list of Lists into L

564

* @param L - List to start with

565

* @param Ls - Lists to patch

566

* @param depth - Patch depth ('flat' or 'deep')

567

* @param ignore - Types not to merge

568

* @param fill - Types to be replaced

569

* @returns Patched list

570

*/

571

type PatchAll<L extends List, Ls extends List<List>, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = PatchAllImpl<L, Ls, depth, ignore, fill>;

572

```

573

574

### List Utility Operations

575

576

Utility operations for list generation, comparison, and transformation.

577

578

```typescript { .api }

579

/**

580

* Fill a List with N repetitions of A

581

* @param A - Element to fill with

582

* @param N - Number of repetitions

583

* @param L - Initial list (empty by default)

584

* @returns List filled with repeated elements

585

*/

586

type Repeat<A extends any, N extends number, L extends List = []> = RepeatImpl<A, N, L>;

587

588

/**

589

* Transform a List into a Union

590

* @param L - List to transform

591

* @returns Union of all list elements

592

*/

593

type UnionOf<L extends List> = L[number];

594

595

/**

596

* Remove a dimension from nested L

597

* @param L - List to un-nest

598

* @param strict - Whether to preserve tuples

599

* @returns Flattened list

600

*/

601

type UnNest<L extends List, strict extends Boolean = 1> = UnNestImpl<L, strict>;

602

603

/**

604

* Get the longest List of L & L1

605

* @param L - First list to compare

606

* @param L1 - Second list to compare

607

* @returns Longer of the two lists

608

*/

609

type Longest<L extends List, L1 extends List> = LongestImpl<L, L1>;

610

611

/**

612

* Get the shortest List of L & L1

613

* @param L - First list to compare

614

* @param L1 - Second list to compare

615

* @returns Shorter of the two lists

616

*/

617

type Shortest<L extends List, L1 extends List> = ShortestImpl<L, L1>;

618

619

/**

620

* Split L into a Union where none of the K keys are present together

621

* @param L - List to split

622

* @param K - Keys to split with

623

* @param strict - Force excess property checks

624

* @returns List union with mutually exclusive keys

625

*/

626

type Either<L extends List, K extends Key, strict extends Boolean = 1> = OEither<ObjectOf<L>, `${K & number}` | K, strict> extends infer OE ? OE extends unknown ? _ListOf<OE & {}> : never : never;

627

```

628

629

### Property Modifications

630

631

Modify characteristics of list elements like optionality, nullability, and readonly status.

632

633

```typescript { .api }

634

/**

635

* Make all list elements optional

636

* @param L - List to make partial

637

* @returns List with optional elements

638

*/

639

type Partial<L extends List> = { [K in keyof L]?: L[K] };

640

641

/**

642

* Make all list elements required

643

* @param L - List to make required

644

* @returns List with required elements

645

*/

646

type Required<L extends List> = { [K in keyof L]-?: L[K] };

647

648

/**

649

* Make all list elements readonly

650

* @param L - List to make readonly

651

* @returns Readonly list

652

*/

653

type Readonly<L extends List> = { readonly [K in keyof L]: L[K] };

654

655

/**

656

* Make all list elements writable

657

* @param L - List to make writable

658

* @returns Writable list

659

*/

660

type Writable<L extends List> = { -readonly [K in keyof L]: L[K] };

661

662

/**

663

* Make all list elements nullable

664

* @param L - List to make nullable

665

* @returns List with nullable elements

666

*/

667

type Nullable<L extends List> = { [K in keyof L]: L[K] | null };

668

669

/**

670

* Remove null and undefined from all list elements

671

* @param L - List to make non-nullable

672

* @returns List with non-nullable elements

673

*/

674

type NonNullable<L extends List> = { [K in keyof L]: NonNullable<L[K]> };

675

676

/**

677

* Make all list elements undefinable

678

* @param L - List to make undefinable

679

* @returns List with undefinable elements

680

*/

681

type Undefinable<L extends List> = { [K in keyof L]: L[K] | undefined };

682

```

683

684

**Usage Examples:**

685

686

```typescript

687

import { L } from "ts-toolbelt";

688

689

type StrictList = readonly [string, number, boolean];

690

691

type OptionalList = L.Partial<StrictList>; // [string?, number?, boolean?]

692

type RequiredList = L.Required<OptionalList>; // [string, number, boolean]

693

type ReadonlyList = L.Readonly<[string, number]>; // readonly [string, number]

694

type WritableList = L.Writable<ReadonlyList>; // [string, number]

695

696

type NullableList = L.Nullable<[string, number]>; // [string | null, number | null]

697

type NonNullList = L.NonNullable<[string | null, number | undefined]>; // [string, number]

698

type UndefinableList = L.Undefinable<[string, number]>; // [string | undefined, number | undefined]

699

```

700

701

### Advanced Operations

702

703

Complex operations for merging, updating, and transforming lists.

704

705

```typescript { .api }

706

/**

707

* Merge two lists element-wise

708

* @param L1 - First list

709

* @param L2 - Second list

710

* @returns Merged list

711

*/

712

type Merge<L1 extends List, L2 extends List> = MergeImpl<L1, L2>;

713

714

/**

715

* Merge multiple lists

716

* @param Ls - Array of lists to merge

717

* @returns Single merged list

718

*/

719

type MergeAll<Ls extends readonly List[]> = MergeAllImpl<Ls>;

720

721

/**

722

* Update element at specific index

723

* @param L - List to update

724

* @param K - Index to update

725

* @param A - New value

726

* @returns List with updated element

727

*/

728

type Update<L extends List, K extends number, A> = UpdateImpl<L, K, A>;

729

730

/**

731

* Remove elements at specific indices

732

* @param L - List to remove from

733

* @param K - Indices to remove

734

* @returns List without removed elements

735

*/

736

type Remove<L extends List, K extends number> = RemoveImpl<L, K>;

737

738

/**

739

* Replace all occurrences of element

740

* @param L - List to replace in

741

* @param From - Element to replace

742

* @param To - Replacement element

743

* @returns List with replacements

744

*/

745

type Replace<L extends List, From, To> = ReplaceImpl<L, From, To>;

746

747

/**

748

* Select elements based on condition

749

* @param L - List to select from

750

* @param C - Selection condition

751

* @returns Selected elements

752

*/

753

type Select<L extends List, C> = SelectImpl<L, C>;

754

755

/**

756

* Convert list to union type

757

* @param L - List to unionize

758

* @returns Union of all list elements

759

*/

760

type Unionize<L extends List> = L[number];

761

```

762

763

**Usage Examples:**

764

765

```typescript

766

import { L } from "ts-toolbelt";

767

768

type List1 = [1, 2, 3];

769

type List2 = ["a", "b", "c"];

770

771

type Merged = L.Merge<List1, List2>; // [1 | "a", 2 | "b", 3 | "c"]

772

type MergedMultiple = L.MergeAll<[List1, List2, [true, false, true]]>;

773

// [1 | "a" | true, 2 | "b" | false, 3 | "c" | true]

774

775

type Updated = L.Update<[1, 2, 3], 1, "two">; // [1, "two", 3]

776

type Removed = L.Remove<[1, 2, 3, 4], 1>; // [1, 3, 4]

777

type Replaced = L.Replace<[1, 2, 1, 3], 1, "one">; // ["one", 2, "one", 3]

778

779

type AsUnion = L.Unionize<["a", "b", "c"]>; // "a" | "b" | "c"

780

```

781

782

## Types

783

784

```typescript { .api }

785

// Core types used by List module

786

type List<A = any> = readonly A[];

787

```