type-plus 4.6.1 → 4.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DigitArray, IsPositive } from '../math';
|
|
2
|
-
export declare type CreateTuple<L extends number, T = any> = number extends L ? T[] : IsPositive<L> extends true ? DigitArray.ToTuple<[], DigitArray.FromNumber<L>, T> :
|
|
1
|
+
import { DigitArray, IsPositive, IsWhole } from '../math';
|
|
2
|
+
export declare type CreateTuple<L extends number, T = any, Fail = never> = number extends L ? T[] : IsPositive<L> extends true ? IsWhole<L> extends true ? DigitArray.ToTuple<[], DigitArray.FromNumber<L>, T> : Fail : Fail;
|
package/package.json
CHANGED
|
@@ -32,3 +32,15 @@ test('L = number gets array', () => {
|
|
|
32
32
|
type A = CreateTuple<number, 1>
|
|
33
33
|
isType.equal<true, 1[], A>()
|
|
34
34
|
})
|
|
35
|
+
|
|
36
|
+
test('Non whole number gets never', () => {
|
|
37
|
+
type A = CreateTuple<1.2>
|
|
38
|
+
|
|
39
|
+
isType.equal<true, never, A>()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('can specify fail type', () => {
|
|
43
|
+
type A = CreateTuple<1.2, 1, null>
|
|
44
|
+
|
|
45
|
+
isType.equal<true, null, A>()
|
|
46
|
+
})
|
package/ts/array/CreateTuple.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DigitArray, IsPositive } from '../math'
|
|
1
|
+
import { DigitArray, IsPositive, IsWhole } from '../math'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates `Tuple<T>` with `L` number of elements.
|
|
@@ -6,7 +6,7 @@ import { DigitArray, IsPositive } from '../math'
|
|
|
6
6
|
* @see https://github.com/microsoft/TypeScript/issues/26223#issuecomment-674514787
|
|
7
7
|
* @see https://github.com/microsoft/TypeScript/issues/47874#issuecomment-1039157322
|
|
8
8
|
*/
|
|
9
|
-
export type CreateTuple<L extends number, T = any> =
|
|
10
|
-
number extends L ? T[] : IsPositive<L> extends true
|
|
9
|
+
export type CreateTuple<L extends number, T = any, Fail = never> =
|
|
10
|
+
number extends L ? T[] : IsPositive<L> extends true ? IsWhole<L> extends true
|
|
11
11
|
? DigitArray.ToTuple<[], DigitArray.FromNumber<L>, T>
|
|
12
|
-
:
|
|
12
|
+
: Fail : Fail
|