type-fns 1.17.0 → 1.18.0
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ref:
|
|
3
|
+
* - https://stackoverflow.com/a/67655609/3068233
|
|
4
|
+
* - https://stackoverflow.com/a/73409753/3068233
|
|
5
|
+
*/
|
|
6
|
+
type BuildArrayWith<TCheck extends 'len' | 'min', // todo: support 'max' too?
|
|
7
|
+
TLength extends number, TType, TCurrent extends TType[]> = TCurrent['length'] extends TLength ? TCheck extends 'len' ? [...TCurrent] : [...TCurrent, ...TType[]] : BuildArrayWith<TCheck, TLength, TType, [...TCurrent, TType]>;
|
|
8
|
+
/**
|
|
9
|
+
* declares a type of array with a check on its length
|
|
10
|
+
*/
|
|
11
|
+
type ArrayWith<TCheck extends 'len' | 'min', // todo: support 'max' too?
|
|
12
|
+
TLength extends number, TType> = BuildArrayWith<TCheck, TLength, TType, []>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayWith.js","sourceRoot":"","sources":["../../src/types/ArrayWith.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
describe('ArrayWith', () => {
|
|
5
|
+
(0, test_fns_1.given)('desire for array with min length', () => {
|
|
6
|
+
(0, test_fns_1.then)('we can declare the type', () => {
|
|
7
|
+
let products;
|
|
8
|
+
});
|
|
9
|
+
(0, test_fns_1.then)('it allows arrays of exactly the min length to it', () => {
|
|
10
|
+
const products = ['doughnut']; // 🍩
|
|
11
|
+
});
|
|
12
|
+
(0, test_fns_1.then)('it allows arrays with more than the min length to it', () => {
|
|
13
|
+
const products = ['doughnut', 'waffle']; // 🍩, 🧇
|
|
14
|
+
});
|
|
15
|
+
(0, test_fns_1.then)('it blocks arrays with less than the min length to it', () => {
|
|
16
|
+
// @ts-expect-error; Type '[]' is not assignable to type '[string, ...string[]]'. Source has 0 element(s) but target requires 1.ts(2322)
|
|
17
|
+
const products = []; // 🍩, 🧇
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
(0, test_fns_1.given)('desire for array with exact length', () => {
|
|
21
|
+
(0, test_fns_1.then)('we can declare the type', () => {
|
|
22
|
+
let products;
|
|
23
|
+
});
|
|
24
|
+
(0, test_fns_1.then)('it allows arrays of exactly the desired length to it', () => {
|
|
25
|
+
const products = ['doughnut']; // 🍩
|
|
26
|
+
});
|
|
27
|
+
(0, test_fns_1.then)('it allows arrays with more than the desired length to it', () => {
|
|
28
|
+
// @ts-expect-error; Type '[string, string]' is not assignable to type '[string]'.Source has 2 element(s) but target allows only 1.
|
|
29
|
+
const products = ['doughnut', 'waffle']; // 🍩, 🧇
|
|
30
|
+
});
|
|
31
|
+
(0, test_fns_1.then)('it blocks arrays with less than the desired length to it', () => {
|
|
32
|
+
// @ts-expect-error; Type '[]' is not assignable to type '[string]'. Source has 0 element(s) but target requires 1.ts(2322)
|
|
33
|
+
const products = [];
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=ArrayWith.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayWith.test.js","sourceRoot":"","sources":["../../src/types/ArrayWith.test.ts"],"names":[],"mappings":";;AAAA,uCAA6C;AAE7C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAA,gBAAK,EAAC,kCAAkC,EAAE,GAAG,EAAE;QAC7C,IAAA,eAAI,EAAC,yBAAyB,EAAE,GAAG,EAAE;YACnC,IAAI,QAAqC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,kDAAkD,EAAE,GAAG,EAAE;YAC5D,MAAM,QAAQ,GAAgC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK;QACnE,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,MAAM,QAAQ,GAAgC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;QACjF,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,wIAAwI;YACxI,MAAM,QAAQ,GAAgC,EAAE,CAAC,CAAC,SAAS;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,IAAA,gBAAK,EAAC,oCAAoC,EAAE,GAAG,EAAE;QAC/C,IAAA,eAAI,EAAC,yBAAyB,EAAE,GAAG,EAAE;YACnC,IAAI,QAAqC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,MAAM,QAAQ,GAAgC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK;QACnE,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,0DAA0D,EAAE,GAAG,EAAE;YACpE,mIAAmI;YACnI,MAAM,QAAQ,GAAgC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;QACjF,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,0DAA0D,EAAE,GAAG,EAAE;YACpE,2HAA2H;YAC3H,MAAM,QAAQ,GAAgC,EAAE,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "type-fns",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "A set of types, type checks, and type guards for simpler, safer, and easier to read code.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.18.0",
|
|
6
6
|
"repository": "ehmpathy/type-fns",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/type-fns",
|
|
8
8
|
"keywords": [
|