Sha256: c6e23745504b016ed3ffbe637d69bcc2145d598ecd8bafa4892cafbac09d5fcf

Contents?: true

Size: 1.09 KB

Versions: 26

Compression:

Stored size: 1.09 KB

Contents

import type {IsNever} from './is-never';
import type {UnionToIntersection} from './union-to-intersection';

/**
Returns the last element of a union type.

@example
```
type Last = LastOfUnion<1 | 2 | 3>;
//=> 3
```
*/
type LastOfUnion<T> =
UnionToIntersection<T extends any ? () => T : never> extends () => (infer R)
	? R
	: never;

/**
Convert a union type into an unordered tuple type of its elements.

This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.

@example
```
import type {UnionToTuple} from 'type-fest';

type Numbers = 1 | 2 | 3;
type NumbersTuple = UnionToTuple<Numbers>;
//=> [1, 2, 3]
```

@example
```
import type {UnionToTuple} from 'type-fest';

const pets = {
  dog: '🐶',
  cat: '🐱',
  snake: '🐍',
};

type Pet = keyof typeof pets;
//=> 'dog' | 'cat' | 'snake'

const petList = Object.keys(pets) as UnionToTuple<Pet>;
//=> ['dog', 'cat', 'snake']
```

@category Array
*/
export type UnionToTuple<T, L = LastOfUnion<T>> =
IsNever<T> extends false
	? [...UnionToTuple<Exclude<T, L>>, L]
	: [];

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/type-fest/source/union-to-tuple.d.ts