typescript-tuple
Advanced tools
Comparing version 2.0.0 to 2.1.0
import * as utils from './utils'; | ||
/** | ||
* Choose type base on whether or not a tuple is finite | ||
* @example `IsFinite<[0, 1, 2]>` → `true` | ||
* @example `IsFinite<[0, 1, 2, ...number[]]>` → `false` | ||
* @example `IsFinite<[0], 'Finite', 'Infinite'>` → `'Finite'` | ||
* @example `IsFinite<[0, ...number[]], 'Finite', 'Infinite'>` → `Infinite` | ||
* @example IsFinite<[0, 1, 2]> → true | ||
* @example IsFinite<[0, 1, 2, ...number[]]> → false | ||
* @example IsFinite<[0], 'Finite', 'Infinite'> → 'Finite' | ||
* @example IsFinite<[0, ...number[]], 'Finite', 'Infinite'> → Infinite | ||
*/ | ||
@@ -12,3 +12,3 @@ export declare type IsFinite<Tuple extends any[], Finite = true, Infinite = false> = utils.IsFinite<Tuple, Finite, Infinite>; | ||
* Split an infinite tuple into a finite tuple and an array | ||
* @example `SplitInfiniteTuple<[0, 1, 2, ...number[]]>` → `[[0, 1, 2], number[]]` | ||
* @example SplitInfiniteTuple<[0, 1, 2, ...number[]]> → [[0, 1, 2], number[]] | ||
*/ | ||
@@ -18,3 +18,3 @@ export declare type SplitInfiniteTuple<Tuple extends any[]> = utils.SplitInfiniteTuple<Tuple>; | ||
* Get type of first element | ||
* @example `First<[0, 1, 2]>` → `0` | ||
* @example First<[0, 1, 2]> → 0 | ||
*/ | ||
@@ -24,8 +24,65 @@ export declare type First<Tuple extends [any, ...any[]]> = Tuple[0]; | ||
* Get type of last element | ||
* @example `Last<[0, 1, 2]>` → `2` | ||
* @example Last<[0, 1, 2]> → 2 | ||
*/ | ||
export declare type Last<Tuple extends any[]> = utils.Last<Tuple>; | ||
/** | ||
* Find index of a type in tuple | ||
* @example FirstIndexEqual<'x', ['a', 'b', 'c', 'x', 'd']> → 3 | ||
* @example FirstIndexEqual<'x', ['a', 'b', 'c']> → never | ||
* @example FirstIndexEqual<'x', ['a', 'b', 'c'], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type FirstIndexEqual<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexEqual<Type, Tuple, NotFound>; | ||
/** | ||
* Find index of the first element in tuple that satifies a type | ||
* @example FirstIndexSubset<string, [true, false, 'x', 3]> → 2 | ||
* @example FirstIndexSubset<string, [true, false, 0, 1]> → never | ||
* @example FirstIndexSubset<string, [true, false, 0, 1], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type FirstIndexSubset<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexSubset<Type, Tuple, NotFound>; | ||
/** | ||
* Find index of the first element in tuple that satifies a type | ||
* @example FirstIndexSuperset<5, [boolean, string, number, object]> → 2 | ||
* @example FirstIndexSuperset<5, [boolean, string, object]> → never | ||
* @example FirstIndexSuperset<5, [boolean, string, object], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type FirstIndexSuperset<Type, Tuple extends any[], NotFound = never> = utils.FirstIndexSuperset<Type, Tuple, NotFound>; | ||
/** | ||
* Find index of a type in tuple | ||
* @example LastIndexEqual<'x', ['a', 'b', 'c', 'x', 'd']> → 3 | ||
* @example LastIndexEqual<'x', ['a', 'b', 'c']> → never | ||
* @example LastIndexEqual<'x', ['a', 'b', 'c'], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type LastIndexEqual<Type, Tuple extends any[], NotFound = never> = utils.LastIndexEqual<Type, Tuple, NotFound>; | ||
/** | ||
* Find index of the first element in tuple that satifies a type | ||
* @example LastIndexSubset<string, [true, false, 'x', 3]> → 2 | ||
* @example LastIndexSubset<string, [true, false, 0, 1]> → never | ||
* @example LastIndexSubset<string, [true, false, 0, 1], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type LastIndexSubset<Type, Tuple extends any[], NotFound = never> = utils.LastIndexSubset<Type, Tuple, NotFound>; | ||
/** | ||
* Find index of the first element in tuple that satifies a type | ||
* @example LastIndexSuperset<5, [boolean, string, number, object]> → 2 | ||
* @example LastIndexSuperset<5, [boolean, string, object]> → never | ||
* @example LastIndexSuperset<5, [boolean, string, object], 'NotFound'> → 'NotFound' | ||
*/ | ||
export declare type LastIndexSuperset<Type, Tuple extends any[], NotFound = never> = utils.LastIndexSuperset<Type, Tuple, NotFound>; | ||
/** | ||
* Find all indexes of a type in tuple | ||
* @example AllIndexesEqual<'x', ['a', 'b', 'x', 'c', 'x', 'x']> → [2, 4, 5] | ||
*/ | ||
export declare type AllIndexesEqual<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesEqual<Type, Tuple>>; | ||
/** | ||
* Find all indexes of a type in tuple | ||
* @example AllIndexesSubset<string, [0, false, 'a', 1, 'b', 'c']> → [2, 4, 5] | ||
*/ | ||
export declare type AllIndexesSubset<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesSubset<Type, Tuple>>; | ||
/** | ||
* Find all indexes of a type in tuple | ||
* @example AllIndexesSuperset<'x', [number, boolean, string, 0, 'x', 'a' | 'b']> → [2, 4, 5] | ||
*/ | ||
export declare type AllIndexesSuperset<Type, Tuple extends any[]> = utils._IndexesNormalize<utils._AllIndexesSuperset<Type, Tuple>>; | ||
/** | ||
* Add an element to the end of a tuple | ||
* @example `Append<[0, 1, 2], 'new'>` → `[0, 1, 2, 'new']` | ||
* @example Append<[0, 1, 2], 'new'> → [0, 1, 2, 'new'] | ||
*/ | ||
@@ -35,3 +92,3 @@ export declare type Append<Tuple extends any[], Addend> = Reverse<Prepend<Reverse<Tuple>, Addend>>; | ||
* Add an element to the beginning of a tuple | ||
* @example `Prepend<[0, 1, 2], 'new'>` → `['new', 0, 1, 2]` | ||
* @example Prepend<[0, 1, 2], 'new'> → ['new', 0, 1, 2] | ||
*/ | ||
@@ -41,3 +98,3 @@ export declare type Prepend<Tuple extends any[], Addend> = utils.Prepend<Tuple, Addend>; | ||
* Reverse a tuple | ||
* @example `Reverse<[0, 1, 2]>` → `[2, 1, 0]` | ||
* @example Reverse<[0, 1, 2]> → [2, 1, 0] | ||
*/ | ||
@@ -47,3 +104,3 @@ export declare type Reverse<Tuple extends any[]> = utils.Reverse<Tuple>; | ||
* Concat two tuple into one | ||
* @example `Concat<[0, 1, 2], ['a', 'b', 'c']>` → `[0, 1, 2, 'a', 'b', 'c']` | ||
* @example Concat<[0, 1, 2], ['a', 'b', 'c']> → [0, 1, 2, 'a', 'b', 'c'] | ||
*/ | ||
@@ -53,4 +110,4 @@ export declare type Concat<Left extends any[], Right extends any[]> = utils.Concat<Left, Right>; | ||
* Repeat a certain type into a tuple | ||
* @example `Repeat<'foo', 4>` → `['foo', 'foo', 'foo', 'foo']` | ||
* @warning To avoid potential infinite loop, `Count` must be an integer greater than or equal to 0 | ||
* @example Repeat<'foo', 4> → ['foo', 'foo', 'foo', 'foo'] | ||
* @warning To avoid potential infinite loop, Count must be an integer greater than or equal to 0 | ||
*/ | ||
@@ -60,3 +117,3 @@ export declare type Repeat<Type, Count extends number> = utils.Repeat<Type, Count, []>; | ||
* Concat multiple tuples | ||
* @example `ConcatMultiple<[], [0], [1, 2], [3, 4, 5]>` → `[0, 1, 2, 3, 4, 5]` | ||
* @example ConcatMultiple<[], [0], [1, 2], [3, 4, 5]> → [0, 1, 2, 3, 4, 5] | ||
*/ | ||
@@ -66,4 +123,4 @@ export declare type ConcatMultiple<TupleSet extends any[][]> = utils.ConcatMultiple<TupleSet>; | ||
* Create a set of tuple of single element | ||
* @example `SingleTupleSet<[0, 1, 2]>` → `[[0], [1], [2]]` | ||
* @example `SingleTupleSet<[0, 1, 2, ...number[]]>` → `[[0], [1], [2], ...[number][]]` | ||
* @example SingleTupleSet<[0, 1, 2]> → [[0], [1], [2]] | ||
* @example SingleTupleSet<[0, 1, 2, ...number[]]> → [[0], [1], [2], ...[number][]] | ||
*/ | ||
@@ -73,4 +130,4 @@ export declare type SingleTupleSet<Types extends any[]> = utils.SingleTupleSet<Types>; | ||
* Fill a tuple of types | ||
* @example `FillTuple<[0, 1, 2], 'x'>` → `['x', 'x', 'x']` | ||
* @example `FillTuple<any[], 'x'>` → `'x'[]` | ||
* @example FillTuple<[0, 1, 2], 'x'> → ['x', 'x', 'x'] | ||
* @example FillTuple<any[], 'x'> → 'x'[] | ||
*/ | ||
@@ -80,5 +137,5 @@ export declare type FillTuple<Tuple extends any[], Replacement> = utils.FillTuple<Tuple, Replacement>; | ||
* Compare length of two tuple | ||
* @example `CompareLength<[0, 1, 2], ['a', 'b', 'c']>` → `'equal'` | ||
* @example `CompareLength<[0, 1], ['a', 'b', 'c']>` → `'shorterLeft'` | ||
* @example `CompareLength<[0, 1, 2], ['a', 'b']>` → `'shorterRight'` | ||
* @example CompareLength<[0, 1, 2], ['a', 'b', 'c']> → 'equal' | ||
* @example CompareLength<[0, 1], ['a', 'b', 'c']> → 'shorterLeft' | ||
* @example CompareLength<[0, 1, 2], ['a', 'b']> → 'shorterRight' | ||
*/ | ||
@@ -88,6 +145,6 @@ export declare type CompareLength<Left extends any[], Right extends any[]> = utils.CompareLength<Left, Right>; | ||
* Sort two tuples in order of [shorter, longer] | ||
* @example `SortTwoTuple<[0, 1, 2, 3], ['a', 'b']>` → `[['a', 'b'], [0, 1, 2, 3]]` | ||
* @example `SortTwoTuple<[0, 1], ['a', 'b', 'c', 'd']>` → `[[0, 1], ['a', 'b', 'c', 'd']]` | ||
* @example `SortTwoTuple<[0, 1, 2], ['a', 'b', 'c']>` → `[[0, 1, 2], ['a', 'b', 'c']]` | ||
* @example `SortTwoTuple<[0, 1, 2], ['a', 'b', 'c'], 'EQUAL'>` → `'EQUAL'` | ||
* @example SortTwoTuple<[0, 1, 2, 3], ['a', 'b']> → [['a', 'b'], [0, 1, 2, 3]] | ||
* @example SortTwoTuple<[0, 1], ['a', 'b', 'c', 'd']> → [[0, 1], ['a', 'b', 'c', 'd']] | ||
* @example SortTwoTuple<[0, 1, 2], ['a', 'b', 'c']> → [[0, 1, 2], ['a', 'b', 'c']] | ||
* @example SortTwoTuple<[0, 1, 2], ['a', 'b', 'c'], 'EQUAL'> → 'EQUAL' | ||
*/ | ||
@@ -97,3 +154,3 @@ export declare type SortTwoTuple<Left extends any[], Right extends any[], WhenEqual = [Left, Right]> = utils.SortTwoTuple<Left, Right, WhenEqual>; | ||
* Find shortest tuple in a set of tuples | ||
* @example `ShortestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]>` → `[true, false]` | ||
* @example ShortestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]> → [true, false] | ||
*/ | ||
@@ -103,4 +160,4 @@ export declare type ShortestTuple<TupleSet extends [any[], ...any[][]]> = utils.ShortestTuple<TupleSet>; | ||
* Find shortest tuple in a set of tuples | ||
* @example `LongestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]>` → `['a', 'b', 'c', 'd']` | ||
* @example LongestTuple<[[0, 1, 2], [true, false], ['a', 'b', 'c', 'd']]> → ['a', 'b', 'c', 'd'] | ||
*/ | ||
export declare type LongestTuple<TupleSet extends [any[], ...any[][]]> = utils.LongestTuple<TupleSet>; |
@@ -0,1 +1,2 @@ | ||
import { Extends, Equal } from 'typescript-compare'; | ||
export declare type IsFinite<Tuple extends any[], Finite, Infinite> = { | ||
@@ -12,2 +13,3 @@ empty: Finite; | ||
}[Tuple extends (infer Element)[] ? Element[] extends Tuple ? 'matched' : 'unmatched' : never]; | ||
export declare type First<Tuple extends any[], Default = never> = Tuple extends [any, ...any[]] ? Tuple[0] : Default; | ||
export declare type Last<Tuple extends any[], Default = never> = { | ||
@@ -19,2 +21,37 @@ empty: Default; | ||
}[Tuple extends [] ? 'empty' : Tuple extends [any] ? 'single' : Tuple extends (infer Element)[] ? Element[] extends Tuple ? 'infinite' : 'multi' : never]; | ||
export declare type FirstIndexEqual<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = { | ||
empty: NotFound; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Equal<First, Type> extends true ? Count['length'] : FirstIndexEqual<Type, Rest, NotFound, Prepend<Count, any>> : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexEqual<Type, Finite, Infinite extends Type[] ? Type[] extends Infinite ? Finite['length'] : NotFound : NotFound> : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type FirstIndexSubset<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = { | ||
empty: NotFound; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Extends<First, Type> extends true ? Count['length'] : FirstIndexSubset<Type, Rest, NotFound, Prepend<Count, any>> : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexSubset<Type, Finite, Infinite extends Type[] ? Finite['length'] : NotFound> : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type FirstIndexSuperset<Type, Tuple extends any[], NotFound = never, Count extends any[] = []> = { | ||
empty: NotFound; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Extends<Type, First> extends true ? Count['length'] : FirstIndexSuperset<Type, Rest, NotFound, Prepend<Count, any>> : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? FirstIndexSuperset<Type, Finite, Extends<Type[], Infinite> extends true ? Finite['length'] : NotFound> : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type LastIndexEqual<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesEqual<Type, Tuple>, NotFound>; | ||
export declare type LastIndexSubset<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesSubset<Type, Tuple>, NotFound>; | ||
export declare type LastIndexSuperset<Type, Tuple extends any[], NotFound = never> = _LastIndexFirst<_AllIndexesSuperset<Type, Tuple>, NotFound>; | ||
export declare type _LastIndexFirst<Tuple extends any[], NotFound> = IsFinite<Tuple, First<Tuple, NotFound>, SplitInfiniteTuple<Tuple> extends [any, infer Infinite] ? Infinite extends (infer X) ? X : never : never>; | ||
export declare type _IndexesNormalize<Indexes extends any[]> = IsFinite<Indexes, Indexes extends any[] ? Reverse<Indexes> : never, SplitInfiniteTuple<Indexes> extends [infer Finite, infer Infinite] ? Finite extends any[] ? ((..._: Finite) => any) extends ((..._: infer Alt) => any) ? Infinite extends any[] ? Concat<Reverse<Alt>, Infinite> : never : never : never : never>; | ||
export declare type _AllIndexesEqual<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = { | ||
empty: Holder; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesEqual<Type, Rest, Equal<First, Type> extends true ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesEqual<Type, Finite, Equal<Last, Type> extends true ? Finite['length'][] : []> : never : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type _AllIndexesSubset<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = { | ||
empty: Holder; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesSubset<Type, Rest, Extends<First, Type> extends true ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesSubset<Type, Finite, Extends<Last, Type> extends true ? Finite['length'][] : []> : never : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type _AllIndexesSuperset<Type, Tuple extends any[], Holder extends any[] = [], Count extends any[] = []> = { | ||
empty: Holder; | ||
nonEmpty: ((..._: Tuple) => any) extends ((_: infer First, ..._1: infer Rest) => any) ? Rest extends any[] ? _AllIndexesSuperset<Type, Rest, Type extends First ? Prepend<Holder, Count['length']> : Holder, Prepend<Count, any>> : never : never; | ||
infinite: SplitInfiniteTuple<Tuple> extends [infer Finite, infer Infinite] ? Finite extends any[] ? Infinite extends (infer Last)[] ? _AllIndexesSuperset<Type, Finite, Type extends Last ? Finite['length'][] : []> : never : never : never; | ||
}[Tuple extends [] ? 'empty' : IsFinite<Tuple, 'nonEmpty', 'infinite'>]; | ||
export declare type Prepend<Tuple extends any[], Addend> = ((_: Addend, ..._1: Tuple) => any) extends ((..._: infer Result) => any) ? Result : never; | ||
@@ -21,0 +58,0 @@ export declare type Reverse<Tuple extends any[], Prefix extends any[] = []> = { |
{ | ||
"name": "typescript-tuple", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Generics to work with tuples in TypeScript", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"build": "pnpm run lint && tsc", | ||
"clean": "clean-typescript-build .", | ||
"lint": "tslint -p .", | ||
"lint:fix": "pnpm run lint -- --fix", | ||
"prepublishOnly": "pnpm run build", | ||
"postpublish": "pnpm run clean", | ||
"test": "tsc --noEmit" | ||
"test": "pnpm run lint && tsc --noEmit" | ||
}, | ||
@@ -28,4 +30,9 @@ "repository": { | ||
"homepage": "https://github.com/ksxnodemodules/typescript-tuple#readme", | ||
"dependencies": { | ||
"typescript-compare": "^0.0.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^3.1.1", | ||
"tslint": "^5.11.0", | ||
"tslint-config-standard": "^8.0.1", | ||
"static-type-assert": "^3.0.0", | ||
@@ -32,0 +39,0 @@ "toolcheck": "^0.0.5", |
120
README.md
@@ -54,2 +54,122 @@ # TypeScript Tuple | ||
### `FirstIndexEqual` | ||
```typescript | ||
import { FirstIndexEqual } from 'typescript-tuple' | ||
type Foo = FirstIndexEqual<'x', ['a', 'x', 'b', 'x']> // Expect: 1 | ||
const foo: Foo = 1 | ||
type Bar = FirstIndexEqual<'x', ['a', 'b']> // Expect: never | ||
type Baz = FirstIndexEqual<'x', ['a', 'b'], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `FirstIndexSubset` | ||
```typescript | ||
import { FirstIndexSubset } from 'typescript-tuple' | ||
type Foo = FirstIndexSubset<string, [0, 'a', 1, 'b']> // Expect: 1 | ||
const foo: Foo = 1 | ||
type Bar = FirstIndexSubset<string, [0, 1]> // Expect: never | ||
type Baz = FirstIndexSubset<string, [0, 1], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `FirstIndexSuperset` | ||
```typescript | ||
import { FirstIndexSuperset } from 'typescript-tuple' | ||
type Foo = FirstIndexSuperset<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: 1 | ||
const foo: Foo = 1 | ||
type Bar = FirstIndexSuperset<'x', [number, 0 | 1]> // Expect: never | ||
type Baz = FirstIndexSuperset<'x', [number, 0 | 1], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `LastIndexEqual` | ||
```typescript | ||
import { LastIndexEqual } from 'typescript-tuple' | ||
type Foo = LastIndexEqual<'x', ['a', 'x', 'b', 'x']> // Expect: 3 | ||
const foo: Foo = 3 | ||
type Bar = LastIndexEqual<'x', ['a', 'b']> // Expect: never | ||
type Baz = LastIndexEqual<'x', ['a', 'b'], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `LastIndexSubset` | ||
```typescript | ||
import { LastIndexSubset } from 'typescript-tuple' | ||
type Foo = LastIndexSubset<string, [0, 'a', 1, 'b']> // Expect: 3 | ||
const foo: Foo = 3 | ||
type Bar = LastIndexSubset<string, [0, 1]> // Expect: never | ||
type Baz = LastIndexSubset<string, [0, 1], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `LastIndexSuperset` | ||
```typescript | ||
import { LastIndexSuperset } from 'typescript-tuple' | ||
type Foo = LastIndexSuperset<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: 3 | ||
const foo: Foo = 3 | ||
type Bar = LastIndexSuperset<'x', [number, 0 | 1]> // Expect: never | ||
type Baz = LastIndexSuperset<'x', [number, 0 | 1], 'not found'> // Expect: 'not found' | ||
const baz: Baz = 'not found' | ||
``` | ||
### `AllIndexesEqual` | ||
```typescript | ||
import { AllIndexesEqual } from 'typescript-tuple' | ||
type Foo = AllIndexesEqual<'x', ['a', 'x', 'b', 'x']> // Expect: [1, 3] | ||
const foo: Foo = [1, 3] | ||
type Bar = AllIndexesEqual<'x', ['a', 'x', 'b', ...'x'[]]> // Expect: [1, ...3[]] | ||
const bar: Bar = [1, 3, 3, 3, 3] | ||
``` | ||
### `AllIndexesSubset` | ||
```typescript | ||
import { AllIndexesSubset } from 'typescript-tuple' | ||
type Foo = AllIndexesSubset<string, [0, 'a', 1, 'b']> // Expect: [1, 3] | ||
const foo: Foo = [1, 3] | ||
type Bar = AllIndexesSubset<string, [0, 'a', 1, ...'b'[]]> // Expect: [1, ...3[]] | ||
const bar: Bar = [1, 3, 3, 3, 3] | ||
``` | ||
### `AllIndexesSuper` | ||
```typescript | ||
import { AllIndexesSuper } from 'typescript-tuple' | ||
type Foo = AllIndexesSuper<'x', [number, string, 0 | 1, 'x' | 'y']> // Expect: [1, 3] | ||
const foo: Foo = [1, 3] | ||
type Bar = AllIndexesSuper<'x', [number, string, 0 | 1, ...'x'[]]> // Expect: [1, ...3[]] | ||
const bar: Bar = [1, 3, 3, 3, 3] | ||
``` | ||
### `Append` | ||
@@ -56,0 +176,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29477
271
318
0
1
6
+ Addedtypescript-compare@^0.0.2
+ Addedtypescript-compare@0.0.2(transitive)
+ Addedtypescript-logic@0.0.0(transitive)