type-plus 6.7.1 → 6.8.1

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.
package/README.md CHANGED
@@ -327,8 +327,6 @@ You can learn more in their respective sections:
327
327
  - [unknown](./ts/unknown/readme.md)
328
328
  - [void](./ts/void/readme.md)
329
329
 
330
- These checks
331
-
332
330
  ## Type Utilities
333
331
 
334
332
  `type-plus` also provides additional type utilities.
@@ -1,15 +1,28 @@
1
1
  import type { AnyFunction } from '../function/any_function.js';
2
2
  import type { RecursivePartial } from '../object/RecursivePartial.js';
3
3
  import type { NoInfer } from '../type/no_infer.js';
4
- export declare namespace stub {
5
- type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>;
6
- }
4
+ /**
5
+ * stub a value.
6
+ * If the value is a function, it will be passed through as-is.
7
+ */
7
8
  export declare function stub<T extends AnyFunction>(stub: T): T;
8
9
  export declare function stub<T>(stub: RecursivePartial<NoInfer<T>>): T;
9
10
  export declare namespace stub {
10
- var build: {
11
- <T>(): (stub?: Param<T> | undefined) => T;
12
- <T_1>(init: RecursivePartial<T_1> | ((stub?: Param<T_1> | undefined) => RecursivePartial<T_1>)): (stub?: Param<T_1> | undefined) => T_1;
11
+ var build: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => (stub?: RecursivePartial<T> | undefined) => T;
12
+ var builder: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => {
13
+ /**
14
+ * Adds an init object or handler to the builder.
15
+ *
16
+ * If `init` is an object, it will be merged with the stub object.
17
+ * If `init` is a function, it will be called with the stub object.
18
+ *
19
+ * @return {Builder<T>} The builder instance.
20
+ */
21
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): any;
22
+ /**
23
+ * Creates the resulting stub function.
24
+ */
25
+ create(): (stub?: RecursivePartial<T> | undefined) => T;
13
26
  };
14
27
  }
15
28
  //# sourceMappingURL=stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,yBAAiB,IAAI,CAAC;IACrB,KAAY,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,GAAG,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;CAC/E;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI"}
1
+ {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI;;;QAqClB;;;;;;;WAOG;;QAIH;;WAEG"}
@@ -7,15 +7,54 @@ function stub(stub) {
7
7
  }
8
8
  exports.stub = stub;
9
9
  function build(init) {
10
- return function (value) {
11
- if (typeof init === 'function') {
12
- return init(value);
13
- }
14
- if (init) {
15
- return (0, unpartial_1.requiredDeep)(init, value);
10
+ return builder(init).create();
11
+ }
12
+ /**
13
+ * Create a builder for a stub function of type T.
14
+ *
15
+ * The builder contains two methods:
16
+ *
17
+ * `.with()`: adds additional handler or partial stub.
18
+ * `.create()`: creates the final stub function.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
23
+ * b({ a: 2 }) // { a: 2, b: 'b' }
24
+ * ```
25
+ */
26
+ function builder(init) {
27
+ return builderInternal([init]);
28
+ }
29
+ function builderInternal(initializers) {
30
+ const builder = {
31
+ /**
32
+ * Adds an init object or handler to the builder.
33
+ *
34
+ * If `init` is an object, it will be merged with the stub object.
35
+ * If `init` is a function, it will be called with the stub object.
36
+ *
37
+ * @return {Builder<T>} The builder instance.
38
+ */
39
+ with(init) {
40
+ return builderInternal([...initializers, init]);
41
+ },
42
+ /**
43
+ * Creates the resulting stub function.
44
+ */
45
+ create() {
46
+ return (stub) => {
47
+ return initializers.reduce((acc, init) => {
48
+ if (typeof init === 'function') {
49
+ return init(acc);
50
+ }
51
+ return (0, unpartial_1.requiredDeep)(init, acc);
52
+ }, stub);
53
+ };
16
54
  }
17
- return value;
18
55
  };
56
+ return builder;
19
57
  }
20
58
  stub.build = build;
59
+ stub.builder = builder;
21
60
  //# sourceMappingURL=stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAWxC,SAAgB,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AAFD,oBAEC;AASD,SAAS,KAAK,CAAI,IAA4E;IAC7F,OAAO,UAAU,KAAqB;QACrC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC/B,OAAO,I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AAA;AAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA"}
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js';
2
+ import type { IsBigint } from '../bigint/bigint_type.js';
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js';
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js';
3
5
  import type { IsFalse } from '../boolean/false_type.js';
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js';
5
7
  import type { IsTrue } from '../boolean/true_type.js';
6
8
  import type { Equal } from '../equal/equal.js';
7
9
  import type { IsNever } from '../never/never_type.js';
8
- import { IsNumber } from '../number/number_type.js';
10
+ import type { IsNull } from '../null/null_type.js';
11
+ import type { IsNumber } from '../number/number_type.js';
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js';
10
13
  import type { CanAssign } from '../predicates/CanAssign.js';
14
+ import type { IsStrictString } from '../string/strict_string_type.js';
15
+ import type { IsString } from '../string/string_type.js';
16
+ import type { IsUndefined } from '../undefined/undefined_type.js';
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js';
12
18
  import type { IsVoid } from '../void/void_type.js';
13
19
  /**
@@ -97,6 +103,42 @@ export declare const testType: {
97
103
  * @return `expected` as `T` for type inspection.
98
104
  */
99
105
  number<T_9>(expected: IsNumber<T_9>): T_9;
106
+ /**
107
+ * Check if type `T` is exactly `string`.
108
+ *
109
+ * @return `expected` as `T` for type inspection.
110
+ */
111
+ strictString<T_10>(expected: IsStrictString<T_10>): T_10;
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string<T_11>(expected: IsString<T_11>): T_11;
118
+ /**
119
+ * Check if type `T` is exactly `bigint`.
120
+ *
121
+ * @return `expected` as `T` for type inspection.
122
+ */
123
+ strictBigint<T_12>(expected: IsStrictBigint<T_12>): T_12;
124
+ /**
125
+ * Check if type `T` is `bigint` or bigint literals.
126
+ *
127
+ * @return `expected` as `T` for type inspection.
128
+ */
129
+ bigint<T_13>(expected: IsBigint<T_13>): T_13;
130
+ /**
131
+ * Check if type `T` is exactly `undefined`.
132
+ *
133
+ * @return `expected` as `T` for type inspection.
134
+ */
135
+ undefined<T_14>(expected: IsUndefined<T_14>): T_14;
136
+ /**
137
+ * Check if type `T` is exactly `null`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ null<T_15>(expected: IsNull<T_15>): T_15;
100
142
  };
101
143
  export {};
102
144
  //# sourceMappingURL=test_type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.d.ts","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GA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AAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAC/D;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAK9C;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;IACpB;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;;IAKH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;CAIH,CAAA"}
@@ -100,6 +100,54 @@ exports.testType = {
100
100
  */
101
101
  number(expected) {
102
102
  return expected;
103
+ },
104
+ /**
105
+ * Check if type `T` is exactly `string`.
106
+ *
107
+ * @return `expected` as `T` for type inspection.
108
+ */
109
+ strictString(expected) {
110
+ return expected;
111
+ },
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string(expected) {
118
+ return expected;
119
+ },
120
+ /**
121
+ * Check if type `T` is exactly `bigint`.
122
+ *
123
+ * @return `expected` as `T` for type inspection.
124
+ */
125
+ strictBigint(expected) {
126
+ return expected;
127
+ },
128
+ /**
129
+ * Check if type `T` is `bigint` or bigint literals.
130
+ *
131
+ * @return `expected` as `T` for type inspection.
132
+ */
133
+ bigint(expected) {
134
+ return expected;
135
+ },
136
+ /**
137
+ * Check if type `T` is exactly `undefined`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ undefined(expected) {
142
+ return expected;
143
+ },
144
+ /**
145
+ * Check if type `T` is exactly `null`.
146
+ *
147
+ * @return `expected` as `T` for type inspection.
148
+ */
149
+ null(expected) {
150
+ return expected;
103
151
  }
104
152
  };
105
153
  //# sourceMappingURL=test_type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":";;;AAyBA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
1
+ {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":";;;AA+BA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,SAAS,CAAI,QAAwB;QACpC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
@@ -1,15 +1,28 @@
1
1
  import type { AnyFunction } from '../function/any_function.js';
2
2
  import type { RecursivePartial } from '../object/RecursivePartial.js';
3
3
  import type { NoInfer } from '../type/no_infer.js';
4
- export declare namespace stub {
5
- type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>;
6
- }
4
+ /**
5
+ * stub a value.
6
+ * If the value is a function, it will be passed through as-is.
7
+ */
7
8
  export declare function stub<T extends AnyFunction>(stub: T): T;
8
9
  export declare function stub<T>(stub: RecursivePartial<NoInfer<T>>): T;
9
10
  export declare namespace stub {
10
- var build: {
11
- <T>(): (stub?: Param<T> | undefined) => T;
12
- <T_1>(init: RecursivePartial<T_1> | ((stub?: Param<T_1> | undefined) => RecursivePartial<T_1>)): (stub?: Param<T_1> | undefined) => T_1;
11
+ var build: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => (stub?: RecursivePartial<T> | undefined) => T;
12
+ var builder: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => {
13
+ /**
14
+ * Adds an init object or handler to the builder.
15
+ *
16
+ * If `init` is an object, it will be merged with the stub object.
17
+ * If `init` is a function, it will be called with the stub object.
18
+ *
19
+ * @return {Builder<T>} The builder instance.
20
+ */
21
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): any;
22
+ /**
23
+ * Creates the resulting stub function.
24
+ */
25
+ create(): (stub?: RecursivePartial<T> | undefined) => T;
13
26
  };
14
27
  }
15
28
  //# sourceMappingURL=stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,yBAAiB,IAAI,CAAC;IACrB,KAAY,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,GAAG,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;CAC/E;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI"}
1
+ {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI;;;QAqClB;;;;;;;WAOG;;QAIH;;WAEG"}
@@ -3,15 +3,54 @@ export function stub(stub) {
3
3
  return stub;
4
4
  }
5
5
  function build(init) {
6
- return function (value) {
7
- if (typeof init === 'function') {
8
- return init(value);
9
- }
10
- if (init) {
11
- return requiredDeep(init, value);
6
+ return builder(init).create();
7
+ }
8
+ /**
9
+ * Create a builder for a stub function of type T.
10
+ *
11
+ * The builder contains two methods:
12
+ *
13
+ * `.with()`: adds additional handler or partial stub.
14
+ * `.create()`: creates the final stub function.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
19
+ * b({ a: 2 }) // { a: 2, b: 'b' }
20
+ * ```
21
+ */
22
+ function builder(init) {
23
+ return builderInternal([init]);
24
+ }
25
+ function builderInternal(initializers) {
26
+ const builder = {
27
+ /**
28
+ * Adds an init object or handler to the builder.
29
+ *
30
+ * If `init` is an object, it will be merged with the stub object.
31
+ * If `init` is a function, it will be called with the stub object.
32
+ *
33
+ * @return {Builder<T>} The builder instance.
34
+ */
35
+ with(init) {
36
+ return builderInternal([...initializers, init]);
37
+ },
38
+ /**
39
+ * Creates the resulting stub function.
40
+ */
41
+ create() {
42
+ return (stub) => {
43
+ return initializers.reduce((acc, init) => {
44
+ if (typeof init === 'function') {
45
+ return init(acc);
46
+ }
47
+ return requiredDeep(init, acc);
48
+ }, stub);
49
+ };
12
50
  }
13
- return value;
14
51
  };
52
+ return builder;
15
53
  }
16
54
  stub.build = build;
55
+ stub.builder = builder;
17
56
  //# sourceMappingURL=stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAWxC,MAAM,UAAU,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AASD,SAAS,KAAK,CAAI,IAA4E;IAC7F,OAAO,UAAU,KAAqB;QACrC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;SAClB;QACD,IAAI,IAAI,EAAE;YACT,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;SAChC;QACD,OAAO,KAAK,CAAA;IACb,CAAC,CAAA;AACF,CAAC;AAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAWxC,MAAM,UAAU,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AAQD,SAAS,KAAK,CAAI,IAAiF;IAClG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,OAAO,CAAI,IAAiF;IACpG,OAAO,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAC/B,CAAC;AAED,SAAS,eAAe,CACvB,YAAgG;IAEhG,MAAM,OAAO,GAAG;QACf;;;;;;;WAOG;QACH,IAAI,CAAC,IAAiF;YACrF,OAAO,eAAe,CAAC,CAAC,GAAG,YAAY,EAAE,IAAI,CAAC,CAAC,CAAA;QAChD,CAAC;QACD;;WAEG;QAEH,MAAM;YACL,OAAO,CAAC,IAA0B,EAAE,EAAE;gBACrC,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;oBACxC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;wBAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;qBAChB;oBACD,OAAO,YAAY,CAAsB,IAAI,EAAE,GAAG,CAAC,CAAA;gBACpD,CAAC,EAAE,IAAI,CAAM,CAAA;YACd,CAAC,CAAA;QACF,CAAC;KACD,CAAA;IACD,OAAO,OAAO,CAAA;AACf,CAAC;AACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;AAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA"}
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js';
2
+ import type { IsBigint } from '../bigint/bigint_type.js';
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js';
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js';
3
5
  import type { IsFalse } from '../boolean/false_type.js';
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js';
5
7
  import type { IsTrue } from '../boolean/true_type.js';
6
8
  import type { Equal } from '../equal/equal.js';
7
9
  import type { IsNever } from '../never/never_type.js';
8
- import { IsNumber } from '../number/number_type.js';
10
+ import type { IsNull } from '../null/null_type.js';
11
+ import type { IsNumber } from '../number/number_type.js';
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js';
10
13
  import type { CanAssign } from '../predicates/CanAssign.js';
14
+ import type { IsStrictString } from '../string/strict_string_type.js';
15
+ import type { IsString } from '../string/string_type.js';
16
+ import type { IsUndefined } from '../undefined/undefined_type.js';
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js';
12
18
  import type { IsVoid } from '../void/void_type.js';
13
19
  /**
@@ -97,6 +103,42 @@ export declare const testType: {
97
103
  * @return `expected` as `T` for type inspection.
98
104
  */
99
105
  number<T_9>(expected: IsNumber<T_9>): T_9;
106
+ /**
107
+ * Check if type `T` is exactly `string`.
108
+ *
109
+ * @return `expected` as `T` for type inspection.
110
+ */
111
+ strictString<T_10>(expected: IsStrictString<T_10>): T_10;
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string<T_11>(expected: IsString<T_11>): T_11;
118
+ /**
119
+ * Check if type `T` is exactly `bigint`.
120
+ *
121
+ * @return `expected` as `T` for type inspection.
122
+ */
123
+ strictBigint<T_12>(expected: IsStrictBigint<T_12>): T_12;
124
+ /**
125
+ * Check if type `T` is `bigint` or bigint literals.
126
+ *
127
+ * @return `expected` as `T` for type inspection.
128
+ */
129
+ bigint<T_13>(expected: IsBigint<T_13>): T_13;
130
+ /**
131
+ * Check if type `T` is exactly `undefined`.
132
+ *
133
+ * @return `expected` as `T` for type inspection.
134
+ */
135
+ undefined<T_14>(expected: IsUndefined<T_14>): T_14;
136
+ /**
137
+ * Check if type `T` is exactly `null`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ null<T_15>(expected: IsNull<T_15>): T_15;
100
142
  };
101
143
  export {};
102
144
  //# sourceMappingURL=test_type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.d.ts","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAA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IH;;;;OAIG;;IAIH;;;;OAIG;;CAIH,CAAA"}
@@ -97,6 +97,54 @@ export const testType = {
97
97
  */
98
98
  number(expected) {
99
99
  return expected;
100
+ },
101
+ /**
102
+ * Check if type `T` is exactly `string`.
103
+ *
104
+ * @return `expected` as `T` for type inspection.
105
+ */
106
+ strictString(expected) {
107
+ return expected;
108
+ },
109
+ /**
110
+ * Check if type `T` is `string` or string literals.
111
+ *
112
+ * @return `expected` as `T` for type inspection.
113
+ */
114
+ string(expected) {
115
+ return expected;
116
+ },
117
+ /**
118
+ * Check if type `T` is exactly `bigint`.
119
+ *
120
+ * @return `expected` as `T` for type inspection.
121
+ */
122
+ strictBigint(expected) {
123
+ return expected;
124
+ },
125
+ /**
126
+ * Check if type `T` is `bigint` or bigint literals.
127
+ *
128
+ * @return `expected` as `T` for type inspection.
129
+ */
130
+ bigint(expected) {
131
+ return expected;
132
+ },
133
+ /**
134
+ * Check if type `T` is exactly `undefined`.
135
+ *
136
+ * @return `expected` as `T` for type inspection.
137
+ */
138
+ undefined(expected) {
139
+ return expected;
140
+ },
141
+ /**
142
+ * Check if type `T` is exactly `null`.
143
+ *
144
+ * @return `expected` as `T` for type inspection.
145
+ */
146
+ null(expected) {
147
+ return expected;
100
148
  }
101
149
  };
102
150
  //# sourceMappingURL=test_type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAyBA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
1
+ {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AA+BA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,SAAS,CAAI,QAAwB;QACpC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-plus",
3
- "version": "6.7.1",
3
+ "version": "6.8.1",
4
4
  "description": "Provides additional types for TypeScript.",
5
5
  "homepage": "https://github.com/unional/type-plus",
6
6
  "bugs": {
@@ -41,7 +41,7 @@
41
41
  "@commitlint/cli": "^17.0.2",
42
42
  "@commitlint/config-conventional": "^17.0.2",
43
43
  "@jest/globals": "^29.5.0",
44
- "@repobuddy/jest": "^3.1.5",
44
+ "@repobuddy/jest": "^3.4.0",
45
45
  "@size-limit/esbuild-why": "^8.2.4",
46
46
  "@size-limit/preset-small-lib": "^8.2.4",
47
47
  "@types/node": "^18.0.0",
@@ -91,6 +91,7 @@
91
91
  "test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
92
92
  "verify": "npm-run-all clean -p build depcheck lint coverage -p size",
93
93
  "version": "changeset version",
94
- "watch": "jest --watch"
94
+ "watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
95
+ "w": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch"
95
96
  }
96
97
  }
@@ -3,10 +3,10 @@ import type { AnyFunction } from '../function/any_function.js'
3
3
  import type { RecursivePartial } from '../object/RecursivePartial.js'
4
4
  import type { NoInfer } from '../type/no_infer.js'
5
5
 
6
- export namespace stub {
7
- export type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>
8
- }
9
-
6
+ /**
7
+ * stub a value.
8
+ * If the value is a function, it will be passed through as-is.
9
+ */
10
10
  export function stub<T extends AnyFunction>(stub: T): T
11
11
  export function stub<T>(stub: RecursivePartial<NoInfer<T>>): T
12
12
  export function stub<T>(stub: unknown): T {
@@ -16,20 +16,62 @@ export function stub<T>(stub: unknown): T {
16
16
  /**
17
17
  * builds a stub function
18
18
  */
19
- function build<T>(): (stub?: stub.Param<T>) => T
20
19
  function build<T>(
21
- init: RecursivePartial<T> | ((stub?: stub.Param<T>) => RecursivePartial<T>)
22
- ): (stub?: stub.Param<T>) => T
23
- function build<T>(init?: RecursivePartial<T> | ((stub?: stub.Param<T>) => RecursivePartial<T>)) {
24
- return function (value?: stub.Param<T>) {
25
- if (typeof init === 'function') {
26
- return init(value)
27
- }
28
- if (init) {
29
- return requiredDeep(init, value)
20
+ init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)
21
+ ): (stub?: RecursivePartial<T>) => T
22
+ function build<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
23
+ return builder(init).create()
24
+ }
25
+
26
+ /**
27
+ * Create a builder for a stub function of type T.
28
+ *
29
+ * The builder contains two methods:
30
+ *
31
+ * `.with()`: adds additional handler or partial stub.
32
+ * `.create()`: creates the final stub function.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
37
+ * b({ a: 2 }) // { a: 2, b: 'b' }
38
+ * ```
39
+ */
40
+ function builder<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
41
+ return builderInternal([init])
42
+ }
43
+
44
+ function builderInternal<T>(
45
+ initializers: Array<RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)>
46
+ ) {
47
+ const builder = {
48
+ /**
49
+ * Adds an init object or handler to the builder.
50
+ *
51
+ * If `init` is an object, it will be merged with the stub object.
52
+ * If `init` is a function, it will be called with the stub object.
53
+ *
54
+ * @return {Builder<T>} The builder instance.
55
+ */
56
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
57
+ return builderInternal([...initializers, init])
58
+ },
59
+ /**
60
+ * Creates the resulting stub function.
61
+ */
62
+
63
+ create() {
64
+ return (stub?: RecursivePartial<T>) => {
65
+ return initializers.reduce((acc, init) => {
66
+ if (typeof init === 'function') {
67
+ return init(acc)
68
+ }
69
+ return requiredDeep<RecursivePartial<T>>(init, acc)
70
+ }, stub) as T
71
+ }
30
72
  }
31
- return value
32
73
  }
74
+ return builder
33
75
  }
34
-
35
76
  stub.build = build
77
+ stub.builder = builder
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js'
2
+ import type { IsBigint } from '../bigint/bigint_type.js'
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js'
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js'
3
5
  import type { IsFalse } from '../boolean/false_type.js'
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js'
5
7
  import type { IsTrue } from '../boolean/true_type.js'
6
8
  import type { Equal } from '../equal/equal.js'
7
9
  import type { IsNever } from '../never/never_type.js'
8
- import { IsNumber } from '../number/number_type.js'
10
+ import type { IsNull } from '../null/null_type.js'
11
+ import type { IsNumber } from '../number/number_type.js'
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js'
10
13
  import type { CanAssign } from '../predicates/CanAssign.js'
14
+ import type { IsStrictString } from '../string/strict_string_type.js'
15
+ import type { IsString } from '../string/string_type.js'
16
+ import type { IsUndefined } from '../undefined/undefined_type.js'
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js'
12
18
  import type { IsVoid } from '../void/void_type.js'
13
19
 
@@ -123,5 +129,53 @@ export const testType = {
123
129
  */
124
130
  number<T>(expected: IsNumber<T>) {
125
131
  return expected as T
132
+ },
133
+ /**
134
+ * Check if type `T` is exactly `string`.
135
+ *
136
+ * @return `expected` as `T` for type inspection.
137
+ */
138
+ strictString<T>(expected: IsStrictString<T>) {
139
+ return expected as T
140
+ },
141
+ /**
142
+ * Check if type `T` is `string` or string literals.
143
+ *
144
+ * @return `expected` as `T` for type inspection.
145
+ */
146
+ string<T>(expected: IsString<T>) {
147
+ return expected as T
148
+ },
149
+ /**
150
+ * Check if type `T` is exactly `bigint`.
151
+ *
152
+ * @return `expected` as `T` for type inspection.
153
+ */
154
+ strictBigint<T>(expected: IsStrictBigint<T>) {
155
+ return expected as T
156
+ },
157
+ /**
158
+ * Check if type `T` is `bigint` or bigint literals.
159
+ *
160
+ * @return `expected` as `T` for type inspection.
161
+ */
162
+ bigint<T>(expected: IsBigint<T>) {
163
+ return expected as T
164
+ },
165
+ /**
166
+ * Check if type `T` is exactly `undefined`.
167
+ *
168
+ * @return `expected` as `T` for type inspection.
169
+ */
170
+ undefined<T>(expected: IsUndefined<T>) {
171
+ return expected as T
172
+ },
173
+ /**
174
+ * Check if type `T` is exactly `null`.
175
+ *
176
+ * @return `expected` as `T` for type inspection.
177
+ */
178
+ null<T>(expected: IsNull<T>) {
179
+ return expected as T
126
180
  }
127
181
  }
@@ -1,7 +1,6 @@
1
- # unknown
1
+ # Tuple
2
2
 
3
- `unknown` is one of the top type in TypeScript.
4
- It is a "safer" variant of `any` that you cannot use the value until there are some type guards or type assertions to the value.
3
+ A *tuple type* is another sort of `Array` type that knows exactly how many elements it contains, and exactly which types it contains at specific positions.
5
4
 
6
5
  ## Type Checking
7
6
 
@@ -10,18 +9,20 @@ The `TupleType<T>` and friends are used to check if `T` is a tuple, excluding ar
10
9
  ```ts
11
10
  import type { TupleType } from 'type-plus'
12
11
 
13
- type R = TupleType<unknown> // unknown
12
+ type R = TupleType<[]> // []
13
+ type R = TupleType<[1]> // [1]
14
14
 
15
- type R = TupleType<1> // never
15
+ type R = TupleType<number[]> // never
16
+ type R = TupleType<number> // never
16
17
  ```
17
18
 
18
- - [`TupleType<T, Then = T, Else = never>`](unknown_type.ts#L16): check if `T` is `unknown`.
19
- - [`IsUnknown<T, Then = true, Else = false`](unknown_type.ts#L35): is `T` `unknown`.
20
- - [`NotUnknownType<T, Then = T, Else = never>`](unknown_type.ts#L50): check if `T` is not `unknown`.
21
- - [`IsNotUnknown<T, Then = true, Else = false>`](unknown_type.ts#L65): is `T` not `unknown`.
19
+ - [`TupleType<T, Then = T, Else = never>`](tuple_type.ts#L16): check if `T` is a *tuple*.
20
+ - [`IsTuple<T, Then = true, Else = false`](tuple_type.ts#L35): is `T` *tuple*.
21
+ - [`NotTupleType<T, Then = T, Else = never>`](tuple_type.ts#L50): check if `T` is not *tuple*.
22
+ - [`IsNotTuple<T, Then = true, Else = false>`](tuple_type.ts#L65): is `T` not *tuple*.
22
23
 
23
24
  ## References
24
25
 
25
26
  - [Handbook]
26
27
 
27
- [handbook]: https://www.typescriptlang.org/docs/handbook/2/functions.html#unknown
28
+ [handbook]: https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types