type-plus 6.8.0 → 7.0.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.
- package/README.md +1053 -356
- package/cjs/array/{array.d.ts → array.at.d.ts} +4 -14
- package/cjs/array/array.at.d.ts.map +1 -0
- package/cjs/array/{pad_left.js → array.at.js} +1 -1
- package/cjs/array/array.at.js.map +1 -0
- package/cjs/array/array.concat.d.ts +13 -0
- package/cjs/array/array.concat.d.ts.map +1 -0
- package/cjs/array/array.concat.js +3 -0
- package/cjs/array/array.concat.js.map +1 -0
- package/cjs/array/array.entries.d.ts +17 -0
- package/cjs/array/array.entries.d.ts.map +1 -0
- package/cjs/array/array.entries.js +3 -0
- package/cjs/array/array.entries.js.map +1 -0
- package/cjs/array/array.find.d.ts +21 -0
- package/cjs/array/array.find.d.ts.map +1 -0
- package/cjs/array/{find_first.js → array.find.js} +1 -1
- package/cjs/array/array.find.js.map +1 -0
- package/cjs/array/array.find_last.d.ts +17 -0
- package/cjs/array/array.find_last.d.ts.map +1 -0
- package/cjs/array/array.find_last.js +3 -0
- package/cjs/array/array.find_last.js.map +1 -0
- package/cjs/array/array.reverse.d.ts +2 -0
- package/cjs/array/array.reverse.d.ts.map +1 -0
- package/cjs/array/array.reverse.js +3 -0
- package/cjs/array/array.reverse.js.map +1 -0
- package/cjs/array/array.some.d.ts +29 -0
- package/cjs/array/array.some.d.ts.map +1 -0
- package/cjs/array/array.some.js +3 -0
- package/cjs/array/array.some.js.map +1 -0
- package/cjs/array/array_index.d.ts +8 -8
- package/cjs/array/array_index.d.ts.map +1 -1
- package/cjs/array/array_plus.d.ts +9 -1
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.split_at.d.ts +30 -0
- package/cjs/array/array_plus.split_at.d.ts.map +1 -0
- package/cjs/array/array_plus.split_at.js +3 -0
- package/cjs/array/array_plus.split_at.js.map +1 -0
- package/cjs/array/drop.d.ts +2 -2
- package/cjs/array/drop.d.ts.map +1 -1
- package/cjs/array/index.d.ts +4 -5
- package/cjs/array/index.d.ts.map +1 -1
- package/cjs/array/index.js +4 -5
- package/cjs/array/index.js.map +1 -1
- package/cjs/array/pad_start.d.ts +32 -0
- package/cjs/array/pad_start.d.ts.map +1 -0
- package/cjs/array/{find_last.js → pad_start.js} +1 -1
- package/cjs/array/pad_start.js.map +1 -0
- package/cjs/assertion/assert_type.d.ts +3 -0
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js +3 -0
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/bigint/cast.d.ts +10 -0
- package/cjs/bigint/cast.d.ts.map +1 -0
- package/cjs/{array/some.js → bigint/cast.js} +1 -1
- package/cjs/bigint/cast.js.map +1 -0
- package/cjs/equal/equal.d.ts +51 -3
- package/cjs/equal/equal.d.ts.map +1 -1
- package/cjs/functional/Maybe.d.ts +2 -2
- package/cjs/functional/Maybe.d.ts.map +1 -1
- package/cjs/index.d.ts +16 -7
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +6 -1
- package/cjs/index.js.map +1 -1
- package/cjs/math/abs.d.ts +6 -0
- package/cjs/math/abs.d.ts.map +1 -0
- package/cjs/math/{Add.js → abs.js} +1 -1
- package/cjs/math/abs.js.map +1 -0
- package/cjs/math/add.d.ts +7 -0
- package/cjs/math/add.d.ts.map +1 -0
- package/cjs/math/{Max.js → add.js} +1 -1
- package/cjs/math/add.js.map +1 -0
- package/cjs/math/greater_than.d.ts +4 -0
- package/cjs/math/greater_than.d.ts.map +1 -0
- package/cjs/math/greater_than.js +3 -0
- package/cjs/math/greater_than.js.map +1 -0
- package/cjs/math/index.d.ts +6 -6
- package/cjs/math/index.d.ts.map +1 -1
- package/cjs/math/math_plus.d.ts +5 -0
- package/cjs/math/math_plus.d.ts.map +1 -0
- package/cjs/math/math_plus.js +3 -0
- package/cjs/math/math_plus.js.map +1 -0
- package/cjs/math/math_plus.to_negative.d.ts +13 -0
- package/cjs/math/math_plus.to_negative.d.ts.map +1 -0
- package/cjs/math/math_plus.to_negative.js +3 -0
- package/cjs/math/math_plus.to_negative.js.map +1 -0
- package/cjs/math/max.d.ts +4 -0
- package/cjs/math/max.d.ts.map +1 -0
- package/cjs/math/{Abs.js → max.js} +1 -1
- package/cjs/math/max.js.map +1 -0
- package/cjs/math/multiply.d.ts +6 -0
- package/cjs/math/multiply.d.ts.map +1 -0
- package/cjs/{array/array.js → math/multiply.js} +1 -1
- package/cjs/math/multiply.js.map +1 -0
- package/cjs/math/numeric_struct.d.ts +1469 -0
- package/cjs/math/numeric_struct.d.ts.map +1 -0
- package/cjs/math/numeric_struct.js +3 -0
- package/cjs/math/numeric_struct.js.map +1 -0
- package/cjs/math/subtract.d.ts +7 -0
- package/cjs/math/subtract.d.ts.map +1 -0
- package/cjs/math/subtract.js +3 -0
- package/cjs/math/subtract.js.map +1 -0
- package/cjs/nominal/brand.js +2 -2
- package/cjs/nominal/brand.js.map +1 -1
- package/cjs/nominal/flavor.js +2 -2
- package/cjs/nominal/flavor.js.map +1 -1
- package/cjs/number/cast.d.ts +10 -0
- package/cjs/number/cast.d.ts.map +1 -0
- package/cjs/number/cast.js +3 -0
- package/cjs/number/cast.js.map +1 -0
- package/cjs/number/number_array.d.ts +0 -2
- package/cjs/number/number_array.d.ts.map +1 -1
- package/cjs/number/number_array.js +14 -1
- package/cjs/number/number_array.js.map +1 -1
- package/cjs/number/number_plus.d.ts +4 -5
- package/cjs/number/number_plus.d.ts.map +1 -1
- package/cjs/number/strict_number_type.d.ts +12 -0
- package/cjs/number/strict_number_type.d.ts.map +1 -1
- package/cjs/numeric/cast.d.ts +27 -0
- package/cjs/numeric/cast.d.ts.map +1 -0
- package/cjs/numeric/cast.js +3 -0
- package/cjs/numeric/cast.js.map +1 -0
- package/{esm/number → cjs/numeric}/integer.d.ts +2 -0
- package/cjs/numeric/integer.d.ts.map +1 -0
- package/cjs/{number → numeric}/integer.js.map +1 -1
- package/cjs/numeric/negative.d.ts.map +1 -0
- package/cjs/{number → numeric}/negative.js.map +1 -1
- package/cjs/numeric/numeric_plus.d.ts +5 -0
- package/cjs/numeric/numeric_plus.d.ts.map +1 -0
- package/cjs/numeric/numeric_plus.js +3 -0
- package/cjs/numeric/numeric_plus.js.map +1 -0
- package/cjs/numeric/numeric_type.d.ts.map +1 -0
- package/cjs/{number → numeric}/numeric_type.js.map +1 -1
- package/cjs/{number → numeric}/positive.d.ts +2 -2
- package/cjs/numeric/positive.d.ts.map +1 -0
- package/cjs/{number → numeric}/positive.js.map +1 -1
- package/cjs/object/ANotB.d.ts +3 -3
- package/cjs/object/ANotB.d.ts.map +1 -1
- package/cjs/object/Partial.d.ts +6 -0
- package/cjs/object/Partial.d.ts.map +1 -1
- package/cjs/object/Required.d.ts +4 -0
- package/cjs/object/Required.d.ts.map +1 -1
- package/cjs/object/index.d.ts +1 -1
- package/cjs/object/index.d.ts.map +1 -1
- package/cjs/object/object_type.d.ts +1 -1
- package/cjs/object/split.d.ts +3 -1
- package/cjs/object/split.d.ts.map +1 -1
- package/cjs/object/split.js.map +1 -1
- package/cjs/predicates/CanAssign.d.ts +35 -0
- package/cjs/predicates/CanAssign.d.ts.map +1 -1
- package/cjs/predicates/CanAssign.js.map +1 -1
- package/cjs/predicates/Extends.d.ts +2 -2
- package/cjs/predicates/Extends.d.ts.map +1 -1
- package/cjs/predicates/index.d.ts +0 -1
- package/cjs/predicates/index.d.ts.map +1 -1
- package/cjs/predicates/index.js +0 -1
- package/cjs/predicates/index.js.map +1 -1
- package/cjs/testing/stub.d.ts.map +1 -1
- package/cjs/testing/stub.js +4 -3
- package/cjs/testing/stub.js.map +1 -1
- package/cjs/testing/test_type.d.ts +125 -50
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/testing/test_type.js +4 -141
- package/cjs/testing/test_type.js.map +1 -1
- package/cjs/tuple/create_tuple.d.ts +28 -0
- package/cjs/tuple/create_tuple.d.ts.map +1 -0
- package/cjs/{array → tuple}/create_tuple.js.map +1 -1
- package/cjs/tuple/tuple_plus.d.ts +2 -0
- package/cjs/tuple/tuple_plus.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.js +18 -0
- package/cjs/tuple/tuple_plus.js.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts +22 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.js +3 -0
- package/cjs/tuple/tuple_plus.pad_start.js.map +1 -0
- package/cjs/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
- package/cjs/type-guard/is_type.d.ts.map +1 -0
- package/cjs/{predicates/isType.js → type-guard/is_type.js} +8 -2
- package/cjs/type-guard/is_type.js.map +1 -0
- package/esm/array/{array.d.ts → array.at.d.ts} +4 -14
- package/esm/array/array.at.d.ts.map +1 -0
- package/esm/array/array.at.js +2 -0
- package/esm/array/array.at.js.map +1 -0
- package/esm/array/array.concat.d.ts +13 -0
- package/esm/array/array.concat.d.ts.map +1 -0
- package/esm/array/array.concat.js +2 -0
- package/esm/array/array.concat.js.map +1 -0
- package/esm/array/array.entries.d.ts +17 -0
- package/esm/array/array.entries.d.ts.map +1 -0
- package/esm/array/array.entries.js +2 -0
- package/esm/array/array.entries.js.map +1 -0
- package/esm/array/array.find.d.ts +21 -0
- package/esm/array/array.find.d.ts.map +1 -0
- package/esm/array/array.find.js +2 -0
- package/esm/array/array.find.js.map +1 -0
- package/esm/array/array.find_last.d.ts +17 -0
- package/esm/array/array.find_last.d.ts.map +1 -0
- package/esm/array/array.find_last.js +2 -0
- package/esm/array/array.find_last.js.map +1 -0
- package/esm/array/array.reverse.d.ts +2 -0
- package/esm/array/array.reverse.d.ts.map +1 -0
- package/esm/array/array.reverse.js +2 -0
- package/esm/array/array.reverse.js.map +1 -0
- package/esm/array/array.some.d.ts +29 -0
- package/esm/array/array.some.d.ts.map +1 -0
- package/esm/array/array.some.js +2 -0
- package/esm/array/array.some.js.map +1 -0
- package/esm/array/array_index.d.ts +8 -8
- package/esm/array/array_index.d.ts.map +1 -1
- package/esm/array/array_plus.d.ts +9 -1
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.split_at.d.ts +30 -0
- package/esm/array/array_plus.split_at.d.ts.map +1 -0
- package/esm/array/array_plus.split_at.js +2 -0
- package/esm/array/array_plus.split_at.js.map +1 -0
- package/esm/array/drop.d.ts +2 -2
- package/esm/array/drop.d.ts.map +1 -1
- package/esm/array/index.d.ts +4 -5
- package/esm/array/index.d.ts.map +1 -1
- package/esm/array/index.js +4 -5
- package/esm/array/index.js.map +1 -1
- package/esm/array/pad_start.d.ts +32 -0
- package/esm/array/pad_start.d.ts.map +1 -0
- package/esm/array/pad_start.js +2 -0
- package/esm/array/pad_start.js.map +1 -0
- package/esm/assertion/assert_type.d.ts +3 -0
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js +3 -0
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/bigint/cast.d.ts +10 -0
- package/esm/bigint/cast.d.ts.map +1 -0
- package/esm/bigint/cast.js +2 -0
- package/esm/bigint/cast.js.map +1 -0
- package/esm/equal/equal.d.ts +51 -3
- package/esm/equal/equal.d.ts.map +1 -1
- package/esm/functional/Maybe.d.ts +2 -2
- package/esm/functional/Maybe.d.ts.map +1 -1
- package/esm/index.d.ts +16 -7
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -1
- package/esm/math/abs.d.ts +6 -0
- package/esm/math/abs.d.ts.map +1 -0
- package/esm/math/abs.js +2 -0
- package/esm/math/abs.js.map +1 -0
- package/esm/math/add.d.ts +7 -0
- package/esm/math/add.d.ts.map +1 -0
- package/esm/math/add.js +2 -0
- package/esm/math/add.js.map +1 -0
- package/esm/math/greater_than.d.ts +4 -0
- package/esm/math/greater_than.d.ts.map +1 -0
- package/esm/math/greater_than.js +2 -0
- package/esm/math/greater_than.js.map +1 -0
- package/esm/math/index.d.ts +6 -6
- package/esm/math/index.d.ts.map +1 -1
- package/esm/math/math_plus.d.ts +5 -0
- package/esm/math/math_plus.d.ts.map +1 -0
- package/esm/math/math_plus.js +2 -0
- package/esm/math/math_plus.js.map +1 -0
- package/esm/math/math_plus.to_negative.d.ts +13 -0
- package/esm/math/math_plus.to_negative.d.ts.map +1 -0
- package/esm/math/math_plus.to_negative.js +2 -0
- package/esm/math/math_plus.to_negative.js.map +1 -0
- package/esm/math/max.d.ts +4 -0
- package/esm/math/max.d.ts.map +1 -0
- package/esm/math/max.js +2 -0
- package/esm/math/max.js.map +1 -0
- package/esm/math/multiply.d.ts +6 -0
- package/esm/math/multiply.d.ts.map +1 -0
- package/esm/math/multiply.js +2 -0
- package/esm/math/multiply.js.map +1 -0
- package/esm/math/numeric_struct.d.ts +1469 -0
- package/esm/math/numeric_struct.d.ts.map +1 -0
- package/esm/math/numeric_struct.js +2 -0
- package/esm/math/numeric_struct.js.map +1 -0
- package/esm/math/subtract.d.ts +7 -0
- package/esm/math/subtract.d.ts.map +1 -0
- package/esm/math/subtract.js +2 -0
- package/esm/math/subtract.js.map +1 -0
- package/esm/nominal/brand.js +1 -1
- package/esm/nominal/brand.js.map +1 -1
- package/esm/nominal/flavor.js +1 -1
- package/esm/nominal/flavor.js.map +1 -1
- package/esm/number/cast.d.ts +10 -0
- package/esm/number/cast.d.ts.map +1 -0
- package/esm/number/cast.js +2 -0
- package/esm/number/cast.js.map +1 -0
- package/esm/number/number_array.d.ts +1 -2
- package/esm/number/number_array.d.ts.map +1 -1
- package/esm/number/number_array.js +14 -0
- package/esm/number/number_array.js.map +1 -1
- package/esm/number/number_plus.d.ts +4 -5
- package/esm/number/number_plus.d.ts.map +1 -1
- package/esm/number/strict_number_type.d.ts +12 -0
- package/esm/number/strict_number_type.d.ts.map +1 -1
- package/esm/numeric/cast.d.ts +27 -0
- package/esm/numeric/cast.d.ts.map +1 -0
- package/esm/numeric/cast.js +2 -0
- package/esm/numeric/cast.js.map +1 -0
- package/{cjs/number → esm/numeric}/integer.d.ts +2 -0
- package/esm/numeric/integer.d.ts.map +1 -0
- package/esm/{number → numeric}/integer.js.map +1 -1
- package/esm/numeric/negative.d.ts.map +1 -0
- package/esm/{number → numeric}/negative.js.map +1 -1
- package/esm/numeric/numeric_plus.d.ts +5 -0
- package/esm/numeric/numeric_plus.d.ts.map +1 -0
- package/esm/numeric/numeric_plus.js +2 -0
- package/esm/numeric/numeric_plus.js.map +1 -0
- package/esm/numeric/numeric_type.d.ts.map +1 -0
- package/esm/{number → numeric}/numeric_type.js.map +1 -1
- package/esm/{number → numeric}/positive.d.ts +2 -2
- package/esm/numeric/positive.d.ts.map +1 -0
- package/esm/{number → numeric}/positive.js.map +1 -1
- package/esm/object/ANotB.d.ts +3 -3
- package/esm/object/ANotB.d.ts.map +1 -1
- package/esm/object/Partial.d.ts +6 -0
- package/esm/object/Partial.d.ts.map +1 -1
- package/esm/object/Required.d.ts +4 -0
- package/esm/object/Required.d.ts.map +1 -1
- package/esm/object/index.d.ts +1 -1
- package/esm/object/index.d.ts.map +1 -1
- package/esm/object/object_type.d.ts +1 -1
- package/esm/object/split.d.ts +3 -1
- package/esm/object/split.d.ts.map +1 -1
- package/esm/object/split.js.map +1 -1
- package/esm/predicates/CanAssign.d.ts +35 -0
- package/esm/predicates/CanAssign.d.ts.map +1 -1
- package/esm/predicates/CanAssign.js.map +1 -1
- package/esm/predicates/Extends.d.ts +2 -2
- package/esm/predicates/Extends.d.ts.map +1 -1
- package/esm/predicates/index.d.ts +0 -1
- package/esm/predicates/index.d.ts.map +1 -1
- package/esm/predicates/index.js +0 -1
- package/esm/predicates/index.js.map +1 -1
- package/esm/testing/stub.d.ts.map +1 -1
- package/esm/testing/stub.js +4 -3
- package/esm/testing/stub.js.map +1 -1
- package/esm/testing/test_type.d.ts +125 -50
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/testing/test_type.js +4 -141
- package/esm/testing/test_type.js.map +1 -1
- package/esm/tuple/create_tuple.d.ts +28 -0
- package/esm/tuple/create_tuple.d.ts.map +1 -0
- package/esm/{array → tuple}/create_tuple.js.map +1 -1
- package/esm/tuple/tuple_plus.d.ts +2 -0
- package/esm/tuple/tuple_plus.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.js +2 -0
- package/esm/tuple/tuple_plus.js.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts +22 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.js +2 -0
- package/esm/tuple/tuple_plus.pad_start.js.map +1 -0
- package/esm/{predicates/isType.d.ts → type-guard/is_type.d.ts} +5 -3
- package/esm/type-guard/is_type.d.ts.map +1 -0
- package/esm/{predicates/isType.js → type-guard/is_type.js} +8 -2
- package/esm/type-guard/is_type.js.map +1 -0
- package/package.json +3 -3
- package/ts/array/{array.ts → array.at.ts} +10 -15
- package/ts/array/array.concat.ts +12 -0
- package/ts/array/array.entries.ts +24 -0
- package/ts/array/array.find.ts +32 -0
- package/ts/array/array.find_last.ts +27 -0
- package/ts/array/array.reverse.ts +16 -0
- package/ts/array/array.some.ts +53 -0
- package/ts/array/array_index.ts +16 -10
- package/ts/array/array_plus.split_at.ts +47 -0
- package/ts/array/array_plus.ts +9 -1
- package/ts/array/drop.ts +2 -2
- package/ts/array/index.ts +4 -5
- package/ts/array/pad_start.ts +43 -0
- package/ts/array/readme.md +184 -4
- package/ts/assertion/assert_type.ts +6 -0
- package/ts/assertion/readme.md +132 -1
- package/ts/bigint/cast.ts +13 -0
- package/ts/bigint/readme.md +17 -17
- package/ts/equal/equal.ts +53 -3
- package/ts/equal/readme.md +30 -16
- package/ts/functional/Maybe.ts +2 -2
- package/ts/index.ts +22 -24
- package/ts/math/README.md +97 -7
- package/ts/math/abs.ts +18 -0
- package/ts/math/add.ts +14 -0
- package/ts/math/greater_than.ts +12 -0
- package/ts/math/index.ts +7 -6
- package/ts/math/math_plus.to_negative.ts +22 -0
- package/ts/math/math_plus.ts +4 -0
- package/ts/math/max.ts +13 -0
- package/ts/math/multiply.ts +12 -0
- package/ts/math/numeric_struct.ts +658 -0
- package/ts/math/subtract.ts +14 -0
- package/ts/nominal/brand.ts +1 -1
- package/ts/nominal/flavor.ts +1 -1
- package/ts/number/cast.ts +17 -0
- package/ts/number/number_array.ts +14 -14
- package/ts/number/number_plus.ts +6 -6
- package/ts/number/readme.md +0 -108
- package/ts/number/strict_number_type.ts +12 -0
- package/ts/numeric/cast.ts +28 -0
- package/ts/{number → numeric}/integer.ts +2 -0
- package/ts/numeric/numeric_plus.ts +12 -0
- package/ts/{number → numeric}/positive.ts +2 -2
- package/ts/numeric/readme.md +115 -0
- package/ts/object/ANotB.ts +3 -3
- package/ts/object/Partial.ts +5 -0
- package/ts/object/Required.ts +4 -0
- package/ts/object/index.ts +1 -1
- package/ts/object/object_type.ts +1 -1
- package/ts/object/split.ts +3 -1
- package/ts/predicates/CanAssign.ts +46 -0
- package/ts/predicates/Extends.ts +2 -2
- package/ts/predicates/index.ts +0 -1
- package/ts/testing/stub.ts +7 -4
- package/ts/testing/test_type.ts +131 -88
- package/ts/tuple/create_tuple.ts +42 -0
- package/ts/tuple/readme.md +11 -10
- package/ts/tuple/tuple_plus.pad_start.ts +42 -0
- package/ts/tuple/tuple_plus.ts +1 -0
- package/ts/{predicates/isType.ts → type-guard/is_type.ts} +11 -3
- package/ts/type-guard/readme.md +37 -0
- package/cjs/array/array.d.ts.map +0 -1
- package/cjs/array/array.js.map +0 -1
- package/cjs/array/create_tuple.d.ts +0 -11
- package/cjs/array/create_tuple.d.ts.map +0 -1
- package/cjs/array/find_first.d.ts +0 -6
- package/cjs/array/find_first.d.ts.map +0 -1
- package/cjs/array/find_first.js.map +0 -1
- package/cjs/array/find_last.d.ts +0 -2
- package/cjs/array/find_last.d.ts.map +0 -1
- package/cjs/array/find_last.js.map +0 -1
- package/cjs/array/pad_left.d.ts +0 -6
- package/cjs/array/pad_left.d.ts.map +0 -1
- package/cjs/array/pad_left.js.map +0 -1
- package/cjs/array/some.d.ts +0 -8
- package/cjs/array/some.d.ts.map +0 -1
- package/cjs/array/some.js.map +0 -1
- package/cjs/math/Abs.d.ts +0 -3
- package/cjs/math/Abs.d.ts.map +0 -1
- package/cjs/math/Abs.js.map +0 -1
- package/cjs/math/Add.d.ts +0 -19
- package/cjs/math/Add.d.ts.map +0 -1
- package/cjs/math/Add.js.map +0 -1
- package/cjs/math/Digit.d.ts +0 -100
- package/cjs/math/Digit.d.ts.map +0 -1
- package/cjs/math/Digit.js +0 -3
- package/cjs/math/Digit.js.map +0 -1
- package/cjs/math/GreaterThan.d.ts +0 -13
- package/cjs/math/GreaterThan.d.ts.map +0 -1
- package/cjs/math/GreaterThan.js +0 -3
- package/cjs/math/GreaterThan.js.map +0 -1
- package/cjs/math/Max.d.ts +0 -4
- package/cjs/math/Max.d.ts.map +0 -1
- package/cjs/math/Max.js.map +0 -1
- package/cjs/math/Subtract.d.ts +0 -19
- package/cjs/math/Subtract.d.ts.map +0 -1
- package/cjs/math/Subtract.js +0 -3
- package/cjs/math/Subtract.js.map +0 -1
- package/cjs/number/integer.d.ts.map +0 -1
- package/cjs/number/negative.d.ts.map +0 -1
- package/cjs/number/numeric_type.d.ts.map +0 -1
- package/cjs/number/positive.d.ts.map +0 -1
- package/cjs/predicates/isType.d.ts.map +0 -1
- package/cjs/predicates/isType.js.map +0 -1
- package/esm/array/array.d.ts.map +0 -1
- package/esm/array/array.js +0 -2
- package/esm/array/array.js.map +0 -1
- package/esm/array/create_tuple.d.ts +0 -11
- package/esm/array/create_tuple.d.ts.map +0 -1
- package/esm/array/find_first.d.ts +0 -6
- package/esm/array/find_first.d.ts.map +0 -1
- package/esm/array/find_first.js +0 -2
- package/esm/array/find_first.js.map +0 -1
- package/esm/array/find_last.d.ts +0 -2
- package/esm/array/find_last.d.ts.map +0 -1
- package/esm/array/find_last.js +0 -2
- package/esm/array/find_last.js.map +0 -1
- package/esm/array/pad_left.d.ts +0 -6
- package/esm/array/pad_left.d.ts.map +0 -1
- package/esm/array/pad_left.js +0 -2
- package/esm/array/pad_left.js.map +0 -1
- package/esm/array/some.d.ts +0 -8
- package/esm/array/some.d.ts.map +0 -1
- package/esm/array/some.js +0 -2
- package/esm/array/some.js.map +0 -1
- package/esm/math/Abs.d.ts +0 -3
- package/esm/math/Abs.d.ts.map +0 -1
- package/esm/math/Abs.js +0 -2
- package/esm/math/Abs.js.map +0 -1
- package/esm/math/Add.d.ts +0 -19
- package/esm/math/Add.d.ts.map +0 -1
- package/esm/math/Add.js +0 -2
- package/esm/math/Add.js.map +0 -1
- package/esm/math/Digit.d.ts +0 -100
- package/esm/math/Digit.d.ts.map +0 -1
- package/esm/math/Digit.js +0 -2
- package/esm/math/Digit.js.map +0 -1
- package/esm/math/GreaterThan.d.ts +0 -13
- package/esm/math/GreaterThan.d.ts.map +0 -1
- package/esm/math/GreaterThan.js +0 -2
- package/esm/math/GreaterThan.js.map +0 -1
- package/esm/math/Max.d.ts +0 -4
- package/esm/math/Max.d.ts.map +0 -1
- package/esm/math/Max.js +0 -2
- package/esm/math/Max.js.map +0 -1
- package/esm/math/Subtract.d.ts +0 -19
- package/esm/math/Subtract.d.ts.map +0 -1
- package/esm/math/Subtract.js +0 -2
- package/esm/math/Subtract.js.map +0 -1
- package/esm/number/integer.d.ts.map +0 -1
- package/esm/number/negative.d.ts.map +0 -1
- package/esm/number/numeric_type.d.ts.map +0 -1
- package/esm/number/positive.d.ts.map +0 -1
- package/esm/predicates/isType.d.ts.map +0 -1
- package/esm/predicates/isType.js.map +0 -1
- package/ts/array/create_tuple.ts +0 -17
- package/ts/array/find_first.ts +0 -16
- package/ts/array/find_last.ts +0 -11
- package/ts/array/pad_left.ts +0 -16
- package/ts/array/some.ts +0 -33
- package/ts/math/Abs.ts +0 -7
- package/ts/math/Add.ts +0 -58
- package/ts/math/Digit.ts +0 -152
- package/ts/math/GreaterThan.ts +0 -55
- package/ts/math/Max.ts +0 -10
- package/ts/math/Subtract.ts +0 -57
- /package/cjs/{number → numeric}/integer.js +0 -0
- /package/cjs/{number → numeric}/negative.d.ts +0 -0
- /package/cjs/{number → numeric}/negative.js +0 -0
- /package/cjs/{number → numeric}/numeric_type.d.ts +0 -0
- /package/cjs/{number → numeric}/numeric_type.js +0 -0
- /package/cjs/{number → numeric}/positive.js +0 -0
- /package/cjs/{array → tuple}/create_tuple.js +0 -0
- /package/esm/{number → numeric}/integer.js +0 -0
- /package/esm/{number → numeric}/negative.d.ts +0 -0
- /package/esm/{number → numeric}/negative.js +0 -0
- /package/esm/{number → numeric}/numeric_type.d.ts +0 -0
- /package/esm/{number → numeric}/numeric_type.js +0 -0
- /package/esm/{number → numeric}/positive.js +0 -0
- /package/esm/{array → tuple}/create_tuple.js +0 -0
- /package/ts/{number → numeric}/negative.ts +0 -0
- /package/ts/{number → numeric}/numeric_type.ts +0 -0
package/README.md
CHANGED
|
@@ -9,15 +9,46 @@
|
|
|
9
9
|
[![Visual Studio Code][vscode_image]][vscode_url]
|
|
10
10
|
[![Wallaby.js][wallaby_image]][wallaby_url]
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
More than 200 type utilities for [TypeScript].
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Assertion Function](#assertion-function)
|
|
17
|
+
1. [assertType](#asserttype)
|
|
18
|
+
2. [Type Guard](#type-guard)
|
|
19
|
+
3. [Type Utilities](#type-utilities)
|
|
20
|
+
4. [Type Checking](#type-checking)
|
|
21
|
+
1. [any](#any)
|
|
22
|
+
2. [Array](#array)
|
|
23
|
+
3. [bigint](#bigint)
|
|
24
|
+
4. [boolean](#boolean)
|
|
25
|
+
5. [function](#function)
|
|
26
|
+
6. [never](#never)
|
|
27
|
+
7. [null](#null)
|
|
28
|
+
8. [number](#number)
|
|
29
|
+
9. [numeric](#numeric)
|
|
30
|
+
10. [object](#object)
|
|
31
|
+
11. [Promise](#promise)
|
|
32
|
+
12. [string](#string)
|
|
33
|
+
13. [symbol](#symbol)
|
|
34
|
+
14. [tuple](#tuple)
|
|
35
|
+
15. [undefined](#undefined)
|
|
36
|
+
16. [unknown](#unknown)
|
|
37
|
+
17. [void](#void)
|
|
38
|
+
5. [Constant Types](#constant-types)
|
|
39
|
+
6. [JSON Support](#json-support)
|
|
40
|
+
7. [Type manipulation](#type-manipulation)
|
|
41
|
+
8. [Type Predicates](#type-predicates)
|
|
42
|
+
1. [Logical](#logical)
|
|
43
|
+
9. [Math](#math)
|
|
44
|
+
10. [Utility Functions](#utility-functions)
|
|
45
|
+
11. [Nominal Types](#nominal-types)
|
|
46
|
+
12. [Functional Types](#functional-types)
|
|
47
|
+
13. [Attribution](#attribution)
|
|
48
|
+
14. [Useful Tips](#useful-tips)
|
|
49
|
+
15. [Similar projects](#similar-projects)
|
|
50
|
+
16. [Contribute](#contribute)
|
|
51
|
+
17. [Wallaby.js](#wallabyjs)
|
|
21
52
|
|
|
22
53
|
## Installation
|
|
23
54
|
|
|
@@ -29,38 +60,29 @@ yarn add type-plus
|
|
|
29
60
|
pnpm add type-plus
|
|
30
61
|
```
|
|
31
62
|
|
|
32
|
-
##
|
|
63
|
+
## Assertion Function
|
|
33
64
|
|
|
34
|
-
|
|
65
|
+
[Assertion Functions][assertion_functions] are special functions that asserts certain conditions of your program.
|
|
35
66
|
|
|
36
|
-
|
|
67
|
+
It is introduced in TypeScript 3.7.
|
|
37
68
|
|
|
38
|
-
|
|
69
|
+
They throw an error if the condition is not met, and return nothing otherwise.
|
|
39
70
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- `logical`: functions or generic types that returns `true` or `false` type to be used in type level programming.
|
|
43
|
-
- `filter`: generic type that returns `never` if the test fails.
|
|
71
|
+
These assertion functions are typically used in runtime,
|
|
72
|
+
so that that type of the value can be narrowed down.
|
|
44
73
|
|
|
45
|
-
|
|
46
|
-
Use the one that fits your specific needs.
|
|
74
|
+
### assertType
|
|
47
75
|
|
|
48
|
-
`assertType
|
|
76
|
+
[`assertType`](./ts/assertion/assert_type.ts) provides a generic assertion function,
|
|
77
|
+
as well as many assertion functions for builtin types.
|
|
49
78
|
|
|
50
|
-
|
|
79
|
+
> [`assertType<T>(subject)`](./ts/assertion/readme.md#asserttype)
|
|
51
80
|
|
|
52
|
-
|
|
53
|
-
It is similar to `const x: T = subject` without introducing an unused variable.
|
|
54
|
-
You need to specify `T` for it to work.
|
|
81
|
+
💀 deprecated. Use `assertType.as()` instead.
|
|
55
82
|
|
|
56
83
|
`assertType<T>(subject, validator)`:
|
|
57
84
|
|
|
58
|
-
`
|
|
59
|
-
|
|
60
|
-
✔️ `assertion function`, `runtime`
|
|
61
|
-
|
|
62
|
-
These overloads of `assertType` allow you to specify a `validator`.
|
|
63
|
-
With these overloads, `subject` can be `unknown` or `any`.
|
|
85
|
+
🚦`assertion`: assert the `subject` is type `T` with the specified `validator`.
|
|
64
86
|
|
|
65
87
|
If `subject` fails the assertion,
|
|
66
88
|
a standard `TypeError` will be thrown and provide better error info.
|
|
@@ -75,189 +97,169 @@ assertType<boolean>(s, s => typeof s === 'boolean')
|
|
|
75
97
|
|
|
76
98
|
The message beautification is provided by [`tersify`](https://github.com/unional/tersify).
|
|
77
99
|
|
|
78
|
-
`assertType.isUndefined(
|
|
100
|
+
> [`assertType.isUndefined()`](./ts/assertion/readme.md#asserttype)
|
|
79
101
|
|
|
80
|
-
`
|
|
102
|
+
🚦`assertion`: assert the `subject` is `undefined`.
|
|
81
103
|
|
|
82
|
-
`assertType.
|
|
104
|
+
> [`assertType.noUndefined()`](./ts/assertion/readme.md#asserttype)
|
|
83
105
|
|
|
84
|
-
`
|
|
106
|
+
🚦`assertion`: assert the `subject` is not `undefined`.
|
|
85
107
|
|
|
86
|
-
`assertType.
|
|
108
|
+
> [`assertType.isNull()`](./ts/assertion/readme.md#asserttype)
|
|
87
109
|
|
|
88
|
-
`
|
|
110
|
+
🚦`assertion`: assert the `subject` is `null`.
|
|
89
111
|
|
|
90
|
-
`assertType.
|
|
112
|
+
> [`assertType.noNull()`](./ts/assertion/readme.md#asserttype)
|
|
91
113
|
|
|
92
|
-
`
|
|
114
|
+
🚦`assertion`: assert the `subject` is not `null`.
|
|
93
115
|
|
|
94
|
-
`assertType.
|
|
116
|
+
> [`assertType.isNumber()`](./ts/assertion/readme.md#asserttype)
|
|
95
117
|
|
|
96
|
-
`
|
|
118
|
+
🚦`assertion`: assert the `subject` is `number`.
|
|
97
119
|
|
|
98
|
-
|
|
120
|
+
> [`assertType.noNumber()`](./ts/assertion/readme.md#asserttype)
|
|
99
121
|
|
|
100
|
-
|
|
101
|
-
They assert the type of `subject` is that specific type.
|
|
102
|
-
i.e. union type will fail at type level:
|
|
122
|
+
🚦`assertion`: assert the `subject` is not `number`.
|
|
103
123
|
|
|
104
|
-
|
|
105
|
-
const s: number | undefined = undefined
|
|
106
|
-
assertType.isUndefined(s) // TypeScript complains
|
|
107
|
-
```
|
|
124
|
+
> [`assertType.isBoolean()`](./ts/assertion/readme.md#asserttype)
|
|
108
125
|
|
|
109
|
-
|
|
126
|
+
🚦`assertion`: assert the `subject` is `boolean`.
|
|
110
127
|
|
|
111
|
-
|
|
112
|
-
const s: any = undefined
|
|
113
|
-
assertType.isUndefined(s)
|
|
114
|
-
s // type is undefined
|
|
115
|
-
```
|
|
128
|
+
> [`assertType.noBoolean()`](./ts/assertion/readme.md#asserttype)
|
|
116
129
|
|
|
117
|
-
`
|
|
130
|
+
🚦`assertion`: assert the `subject` is not `boolean`.
|
|
118
131
|
|
|
119
|
-
|
|
132
|
+
> [`assertType.isTrue()`](./ts/assertion/readme.md#asserttype)
|
|
120
133
|
|
|
121
|
-
|
|
122
|
-
This function is not very useful in actual code as TypeScript will indicate the error.
|
|
123
|
-
But it can be useful when writing tests for types.
|
|
134
|
+
🚦`assertion`: assert the `subject` is `true`.
|
|
124
135
|
|
|
125
|
-
|
|
136
|
+
> [`assertType.noTrue()`](./ts/assertion/readme.md#asserttype)
|
|
126
137
|
|
|
127
|
-
|
|
128
|
-
assertType.isTrue(true as Equal<YourType, never>)
|
|
129
|
-
```
|
|
138
|
+
🚦`assertion`: assert the `subject` is not `true`.
|
|
130
139
|
|
|
131
|
-
`assertType.
|
|
140
|
+
> [`assertType.isFalse()`](./ts/assertion/readme.md#asserttype)
|
|
132
141
|
|
|
133
|
-
`
|
|
142
|
+
🚦`assertion`: assert the `subject` is `false`.
|
|
134
143
|
|
|
135
|
-
`assertType.
|
|
144
|
+
> [`assertType.noFalse()`](./ts/assertion/readme.md#asserttype)
|
|
136
145
|
|
|
137
|
-
`
|
|
146
|
+
🚦`assertion`: assert the `subject` is not `false`.
|
|
138
147
|
|
|
139
|
-
`assertType.
|
|
148
|
+
> [`assertType.isString()`](./ts/assertion/readme.md#asserttype)
|
|
140
149
|
|
|
141
|
-
`
|
|
150
|
+
🚦`assertion`: assert the `subject` is `string`.
|
|
142
151
|
|
|
143
|
-
`assertType.noString(
|
|
152
|
+
> [`assertType.noString()`](./ts/assertion/readme.md#asserttype)
|
|
144
153
|
|
|
145
|
-
`
|
|
154
|
+
🚦`assertion`: assert the `subject` is not `string`.
|
|
146
155
|
|
|
147
|
-
`assertType.
|
|
156
|
+
> [`assertType.isFunction()`](./ts/assertion/readme.md#asserttype)
|
|
148
157
|
|
|
149
|
-
|
|
158
|
+
🚦`assertion`: assert the `subject` is `function`.
|
|
150
159
|
|
|
151
|
-
|
|
152
|
-
Assert `subject` type does not contain the specific type.
|
|
153
|
-
Work against unions.
|
|
160
|
+
> [`assertType.noFunction()`](./ts/assertion/readme.md#asserttype)
|
|
154
161
|
|
|
155
|
-
|
|
156
|
-
const s: number | undefined = 1
|
|
157
|
-
assertType.noUndefined(s) // TypeScript complains
|
|
158
|
-
```
|
|
162
|
+
🚦`assertion`: assert the `subject` is not `function`.
|
|
159
163
|
|
|
160
|
-
|
|
161
|
-
the assertion will happen in runtime to ensure `subject` is the specific type.
|
|
164
|
+
> [`assertType.isError()`](./ts/assertion/readme.md#asserttype)
|
|
162
165
|
|
|
163
|
-
`
|
|
166
|
+
🚦`assertion`: assert the `subject` is an `Error`.
|
|
164
167
|
|
|
165
|
-
|
|
168
|
+
> [`assertType.noError()`](./ts/assertion/readme.md#asserttype)
|
|
166
169
|
|
|
167
|
-
|
|
168
|
-
This is useful to help TypeScript to adjust the type on the fly.
|
|
170
|
+
🚦`assertion`: assert the `subject` is not an `Error`.
|
|
169
171
|
|
|
170
|
-
|
|
171
|
-
let s: number | undefined = 1
|
|
172
|
-
assertType.as<1>(s) // `s` type is now `1`
|
|
173
|
-
```
|
|
172
|
+
> [`assertType.isConstructor()`](./ts/assertion/readme.md#asserttype)
|
|
174
173
|
|
|
175
|
-
|
|
174
|
+
💀 deprecated. It does not work in all cases.
|
|
176
175
|
|
|
177
|
-
|
|
176
|
+
It passes for function that can be called with `new`.
|
|
177
|
+
If the subject is an arrow function, it can still return true after compilation.
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
It is identical to `assertType<T>(subject: T)`.
|
|
181
|
-
You need to specify `T`.
|
|
179
|
+
> [`assertType.isNever()`](./ts/assertion/readme.md#asserttype)
|
|
182
180
|
|
|
183
|
-
`
|
|
181
|
+
🚦`assertion`: assert the `subject` is `never`.
|
|
184
182
|
|
|
185
|
-
`
|
|
183
|
+
> [`assertType.custom()`](./ts/assertion/readme.md#asserttype)
|
|
186
184
|
|
|
187
|
-
|
|
185
|
+
🚦`assertion`: creates a custom assertion function.
|
|
188
186
|
|
|
189
|
-
|
|
187
|
+
Using it to create a custom assertion function that provides better error messages.
|
|
190
188
|
|
|
191
|
-
|
|
192
|
-
or value type check: `isType.t(valueTypeIsTrue)`.
|
|
193
|
-
It returns `true` when passes (which is the only case when used in TypeScript).
|
|
189
|
+
The message beautification is provided by [`tersify`](https://github.com/unional/tersify).
|
|
194
190
|
|
|
195
|
-
`
|
|
191
|
+
> [`assertType.as<T>()`](./ts/assertion/readme.md#asserttype)
|
|
196
192
|
|
|
197
|
-
|
|
193
|
+
🚦`assertion`: assert the `subject` as `T` without validator.
|
|
198
194
|
|
|
199
|
-
|
|
200
|
-
or value type check: `isType.f(valueTypeIsFalse)`.
|
|
201
|
-
It returns `true` when passes (which is the only case when used in TypeScript).
|
|
195
|
+
This works similar to manual assertion `;(subject as T)`
|
|
202
196
|
|
|
203
|
-
|
|
197
|
+
## Type Guard
|
|
204
198
|
|
|
205
|
-
|
|
199
|
+
[User-defined type guard functions][type_guard] is a function which its return type is specified as `x is T`.
|
|
206
200
|
|
|
207
|
-
|
|
208
|
-
when doing type-level only equality comparison as you don't have to import `Equal<>`.
|
|
201
|
+
> [`isType()`](./ts/type-guard/readme.md#istype)
|
|
209
202
|
|
|
210
|
-
|
|
203
|
+
🛡️ `guard`: a generic type guard function
|
|
211
204
|
|
|
212
|
-
|
|
213
|
-
With these overloads, `subject` can be `unknown` or `any`.
|
|
205
|
+
> [`isType.t()`](./ts/type-guard/readme.md#istype)
|
|
214
206
|
|
|
215
|
-
|
|
207
|
+
💀 `deprecated`: use `testType.true()` instead.
|
|
216
208
|
|
|
217
|
-
|
|
209
|
+
> [`isType.f()`](./ts/type-guard/readme.md#istype)
|
|
218
210
|
|
|
219
|
-
|
|
211
|
+
💀 `deprecated`: use `testType.false()` instead.
|
|
220
212
|
|
|
221
|
-
[`isType.never(
|
|
213
|
+
> [`isType.never()`](./ts/type-guard/readme.md#istype)
|
|
222
214
|
|
|
223
|
-
|
|
215
|
+
💀 `deprecated`: use `testType.never()` instead.
|
|
224
216
|
|
|
225
|
-
|
|
217
|
+
> [`isType.equal()`](./ts/type-guard/readme.md#istype)
|
|
226
218
|
|
|
227
|
-
`
|
|
228
|
-
`IsEqual<A, B>`:
|
|
219
|
+
💀 `deprecated`: use `testType.equal()` instead.
|
|
229
220
|
|
|
230
|
-
|
|
221
|
+
## Type Utilities
|
|
231
222
|
|
|
232
|
-
|
|
223
|
+
> `Equal<A, B, Then = true, Else = false>`
|
|
233
224
|
|
|
234
|
-
`
|
|
235
|
-
`IsNotEqual<A, B>`:
|
|
225
|
+
💀 deprecated. use `IsEqual` instead. This will be converted to a ↪️ `parse`.
|
|
236
226
|
|
|
237
|
-
|
|
227
|
+
> `IsEqual<A, B, Then = true, Else = false>`
|
|
238
228
|
|
|
239
|
-
|
|
229
|
+
⭕ `predicate`: if `A` and `B` are the same.
|
|
240
230
|
|
|
241
|
-
`
|
|
242
|
-
`IsNotExtend<A, B>`:
|
|
231
|
+
> `NotEqual<A, B, Then = true, Else = false>`
|
|
243
232
|
|
|
244
|
-
|
|
233
|
+
💀 deprecated. use `IsNotEqual` instead. This will be converted to a ↪️ `parse`.
|
|
245
234
|
|
|
246
|
-
|
|
235
|
+
> `IsNotEqual<A, B, Then = true, Else = false>`:
|
|
247
236
|
|
|
248
|
-
`
|
|
249
|
-
`NotExtendable<A, B>`:
|
|
237
|
+
⭕ `predicate`: check if `A` and `B` are not the same.
|
|
250
238
|
|
|
251
|
-
|
|
239
|
+
> `Extendable<A, B, Then = A, Else = never>`
|
|
252
240
|
|
|
253
|
-
|
|
241
|
+
↪️ `parse`: check if `A` extends `B`.
|
|
254
242
|
|
|
255
|
-
`
|
|
256
|
-
`CanAssign<A, B>`:
|
|
243
|
+
> `IsExtend<A, B, Then = true, Else = false>`
|
|
257
244
|
|
|
258
|
-
|
|
245
|
+
⭕ `predicate`: check if `A` extends `B`.
|
|
246
|
+
|
|
247
|
+
> `NotExtendable<A, B, Then = A, Else = never>`:
|
|
248
|
+
|
|
249
|
+
↪️ `parse`: check if `A` not extends `B`.
|
|
250
|
+
|
|
251
|
+
> `IsNotExtend<A, B, Then = true, Else = false>`:
|
|
252
|
+
|
|
253
|
+
⭕ `predicate`: check if `A` not extends `B`.
|
|
254
|
+
|
|
255
|
+
> `IsAssign<A, B, Then = true, Else = false>`
|
|
256
|
+
|
|
257
|
+
💀 `deprecated`: use `CanAssign` instead.
|
|
258
|
+
|
|
259
|
+
> `CanAssign<A, B, Then = true, Else = false>`:
|
|
260
|
+
|
|
261
|
+
⭕ `predicate`: check can `A` assign to `B`.
|
|
259
262
|
|
|
260
|
-
Check if `A` can be assigned to `B`.
|
|
261
263
|
A typical usage is using it with `assertType`:
|
|
262
264
|
|
|
263
265
|
```ts
|
|
@@ -265,9 +267,20 @@ assertType.isFalse(false as CanAssign<boolean, { a: string }>)
|
|
|
265
267
|
assertType.isTrue(true as CanAssign<{ a:string, b:number }, { a: string }>)
|
|
266
268
|
```
|
|
267
269
|
|
|
268
|
-
`
|
|
270
|
+
> `StrictCanAssign<A, B, Then = true, Else = false>`
|
|
269
271
|
|
|
270
|
-
|
|
272
|
+
⭕ `predicate`: can `A` strictly assign to `B`
|
|
273
|
+
|
|
274
|
+
When `A` is a union, all branches must be assignable to `B`.
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
StrictCanAssign<number | string, number> // false
|
|
278
|
+
StrictCanAssign<number | string, number | string> // true
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
> `canAssign<T>(): (subject) => true`
|
|
282
|
+
|
|
283
|
+
⭕💻 `predicate`, `compile-time`
|
|
271
284
|
|
|
272
285
|
Returns a compile-time validating function to ensure `subject` is assignable to `T`.
|
|
273
286
|
|
|
@@ -276,9 +289,9 @@ const isConfig = canAssign<{ a: string }>()
|
|
|
276
289
|
assertType.isTrue(isConfig({ a: 'a' }))
|
|
277
290
|
```
|
|
278
291
|
|
|
279
|
-
`canAssign<T>(false): (subject) => false`:
|
|
292
|
+
> `canAssign<T>(false): (subject) => false`:
|
|
280
293
|
|
|
281
|
-
|
|
294
|
+
⭕💻 `predicate`, `compile-time`
|
|
282
295
|
|
|
283
296
|
Returns a compile-time validating function to ensure `subject` is not assignable to `T`.
|
|
284
297
|
|
|
@@ -289,17 +302,6 @@ assertType.isTrue(notA({ a: 1 }))
|
|
|
289
302
|
notA({ a: '' }) // TypeScript complains
|
|
290
303
|
```
|
|
291
304
|
|
|
292
|
-
`IsNever<T>`:
|
|
293
|
-
|
|
294
|
-
✔️ `logical`
|
|
295
|
-
|
|
296
|
-
Check if `A` is `never`.
|
|
297
|
-
|
|
298
|
-
```ts
|
|
299
|
-
IsNever<never> // true
|
|
300
|
-
IsNever<1> // false
|
|
301
|
-
```
|
|
302
|
-
|
|
303
305
|
## Type Checking
|
|
304
306
|
|
|
305
307
|
[type-plus](./README.md) privides type checking utilities for every type.
|
|
@@ -327,73 +329,600 @@ You can learn more in their respective sections:
|
|
|
327
329
|
- [unknown](./ts/unknown/readme.md)
|
|
328
330
|
- [void](./ts/void/readme.md)
|
|
329
331
|
|
|
330
|
-
|
|
332
|
+
### any
|
|
331
333
|
|
|
332
|
-
|
|
334
|
+
> [`AnyType<T>`](./ts/any/readme.md#type-checking)
|
|
333
335
|
|
|
334
|
-
`
|
|
335
|
-
These utilities include utility types and type-adjusted functions.
|
|
336
|
+
↪️ `parse`: `T === any`.
|
|
336
337
|
|
|
337
|
-
|
|
338
|
+
> [`IsAny<T>`](./ts/any/readme.md#type-checking)
|
|
338
339
|
|
|
339
|
-
|
|
340
|
+
⭕ `predicate`: `T === any`.
|
|
340
341
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
> [`NotAnyType<T>`](./ts/any/readme.md#type-checking)
|
|
343
|
+
|
|
344
|
+
↪️ `parse`: `T !== any`.
|
|
345
|
+
|
|
346
|
+
> [`IsNotAny<T>`](./ts/any/readme.md#type-checking)
|
|
347
|
+
|
|
348
|
+
⭕ `predicate`: `T !== any`.
|
|
345
349
|
|
|
346
|
-
|
|
350
|
+
> [`IsAnyOrNever<T>`](./ts/any/readme.md#type-utilities)
|
|
347
351
|
|
|
348
|
-
|
|
349
|
-
- [`IsAny<T, Then = true, Else = false>`](ts/any_plus/any.ts#L29): `T === any` (origin: [ts-essentials]).
|
|
352
|
+
⭕ `predicate`: `T === any || T === never`.
|
|
350
353
|
|
|
351
354
|
### Array
|
|
352
355
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
356
|
+
> [`ArrayType<T>`](./ts/array/readme.md#type-checking)
|
|
357
|
+
|
|
358
|
+
↪️ `parse`: is the type `T` exactly an array and not a tuple.
|
|
359
|
+
|
|
360
|
+
> [`IsArray<T>`](./ts/array/readme.md#type-checking)
|
|
361
|
+
|
|
362
|
+
⭕ `predicate`: is the type `T` exactly an array and not a tuple.
|
|
363
|
+
|
|
364
|
+
> [`NotArrayType<T>`](./ts/array/readme.md#type-checking)
|
|
365
|
+
|
|
366
|
+
↪️ `parse`: is the type `T` not an array or tuple.
|
|
367
|
+
|
|
368
|
+
> [`IsNotArray<T>`](./ts/array/readme.md#type-checking)
|
|
369
|
+
|
|
370
|
+
⭕ `predicate`: is the type `T` exactly an array and not a tuple.
|
|
371
|
+
|
|
372
|
+
> [`At<A, N, Fail = never>`](ts/array_plus/array.ts#L19)
|
|
373
|
+
|
|
374
|
+
🔨 `utilities`: gets the element type at index `N` in the array `A`.
|
|
375
|
+
|
|
376
|
+
> `CommonPropKeys<A>`
|
|
377
|
+
|
|
378
|
+
🔨 `utilities`: gets common keys inside the records in the array `A` (deprecate `CommonKeys`).
|
|
379
|
+
|
|
380
|
+
> [`Concat<A, B>`](ts/array_plus/array.ts#L38)
|
|
381
|
+
|
|
382
|
+
🔨 `utilities`: `[...A, ...B]`.
|
|
383
|
+
|
|
384
|
+
> `CreateTuple<L, T>`
|
|
385
|
+
|
|
386
|
+
🔨 `utilities`: creates `tuple<T>` with `L` number of elements.
|
|
387
|
+
|
|
388
|
+
> `drop(array, value)`
|
|
389
|
+
|
|
390
|
+
🔨 `utilities`: drop a particular value from an array.
|
|
391
|
+
|
|
392
|
+
> `DropFirst<A>`
|
|
393
|
+
|
|
394
|
+
🔨 `utilities`: drops the first value type of `A`.
|
|
395
|
+
|
|
396
|
+
> `DropLast<A>`
|
|
397
|
+
|
|
398
|
+
🔨 `utilities`: drops the last value type of `A`.
|
|
399
|
+
|
|
400
|
+
> `DropMatch<A, Criteria>`
|
|
401
|
+
|
|
402
|
+
🔨 `utilities`: drops entries matching `Criteria` in array or tuple `A`.
|
|
403
|
+
|
|
404
|
+
> `DropUndefined<A>`
|
|
405
|
+
|
|
406
|
+
🔨 `utilities`: drop undefined entries from array of tuple `A`.
|
|
407
|
+
|
|
408
|
+
> `Filter<A, Criteria>`
|
|
409
|
+
|
|
410
|
+
💀🔨 `deprecated`,`utilities`: filter the array or tuple `A`, keeping entries satisfying `Criteria`. **Deprecated. Renaming to `KeepMatch`**
|
|
411
|
+
|
|
412
|
+
> `FindFirst<A, Criteria>`
|
|
413
|
+
|
|
414
|
+
🔨 `utilities`: gets the first type satisfying `Criteria`.
|
|
415
|
+
|
|
416
|
+
> `FindLast<A, Criteria>`
|
|
417
|
+
|
|
418
|
+
🔨 `utilities`: gets the last type satisfying `Criteria`.
|
|
419
|
+
|
|
420
|
+
> `Head<A>`
|
|
421
|
+
|
|
422
|
+
🔨 `utilities`: gets the first entry in the array.
|
|
423
|
+
|
|
424
|
+
> `IntersectOfProps<A, K>`
|
|
425
|
+
|
|
426
|
+
🔨 `utilities`: gets the intersect of `A[K]` types (deprecate `MapToProp`)
|
|
427
|
+
|
|
428
|
+
> `KeepMatch<A, Criteria>`
|
|
429
|
+
|
|
430
|
+
🔨 `utilities`: keeps entries satisfying `Criteria` in array or tuple `A`.
|
|
431
|
+
|
|
432
|
+
> `Last<A>`
|
|
433
|
+
|
|
434
|
+
🔨 `utilities`: gets the last type of array or tuple.
|
|
435
|
+
|
|
436
|
+
> `literalArray(...entries)`
|
|
437
|
+
|
|
438
|
+
🔨 `utilities`: return an array whose items are restricted to the provided literals.
|
|
439
|
+
|
|
440
|
+
> `PadLeft<A, Total, PadWith>`
|
|
441
|
+
|
|
442
|
+
🔨 `utilities`: pads `A` with `PadWith` if the length of `A` is less than `L`.
|
|
443
|
+
|
|
444
|
+
> `reduceWhile()`
|
|
445
|
+
|
|
446
|
+
🔨 `utilities`: `reduce()` with predicate for early termination. \
|
|
373
447
|
A simple version of the same function in the `ramda` package.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
448
|
+
|
|
449
|
+
> `Reverse<A>`
|
|
450
|
+
|
|
451
|
+
🔨 `utilities`: reverses the order of `A`.
|
|
452
|
+
|
|
453
|
+
> `Some<A, Criteria>`
|
|
454
|
+
|
|
455
|
+
🔨 `utilities`: true if some elements in `A` matches `Criteria`.
|
|
456
|
+
|
|
457
|
+
> `Tail<A>`
|
|
458
|
+
|
|
459
|
+
🔨 `utilities`: Gets the types of a tuple except the first entry.
|
|
460
|
+
|
|
461
|
+
> `UnionOfProps<A, K>`
|
|
462
|
+
|
|
463
|
+
🔨 `utilities`: gets the union of `A[K]` types (deprecate `PropUnion`).
|
|
464
|
+
|
|
465
|
+
> `UnionOfValues<A>`
|
|
466
|
+
|
|
467
|
+
🔨 `utilities`: gets the union of value types in `A` (deprecate `ArrayValue`).
|
|
468
|
+
|
|
469
|
+
> [`ArrayPlus.IndexAt<A, N, Fail = never>`](ts/array_plus/array_plus.ts#L23)
|
|
470
|
+
|
|
471
|
+
🔨 `utilities`: gets the normalized index for `A`.
|
|
472
|
+
|
|
473
|
+
> [`ArrayPlus.IsIndexOutOfBound<A, N, Then = true, Else = false>`](ts/array_plus/array_plus.ts#L62)
|
|
474
|
+
|
|
475
|
+
⭕ `predicate`: is `N` an out of bound index of `A`. Supports negative numbers.
|
|
476
|
+
|
|
477
|
+
### bigint
|
|
478
|
+
|
|
479
|
+
> [`BigintType<T, Then = T, Else = never>`](./ts/bigint/bigint_type.ts#L15)
|
|
480
|
+
|
|
481
|
+
↪️ `parse`: if `T` is `bigint` or bigint literal.
|
|
482
|
+
|
|
483
|
+
> [`IsBigint<T, Then = true, Else = false>`](./ts/bigint/bigint_type.ts#L33)
|
|
484
|
+
|
|
485
|
+
⭕ `predicate`: if `T` is `bigint` or bigint literal.
|
|
486
|
+
|
|
487
|
+
> [`NotBigintType<T, Then = T, Else = never>`](./ts/bigint/bigint_type.ts#L47)
|
|
488
|
+
|
|
489
|
+
↪️ `parse`: if `T` is not `bigint` or bigint literal.
|
|
490
|
+
|
|
491
|
+
> [`IsNotBigInt<T, Then = true, Else = false>`](./ts/bigint/bigint_type.ts#L61)
|
|
492
|
+
|
|
493
|
+
⭕ `predicate`: if `T` is not `bigint` or bigint literal.
|
|
494
|
+
|
|
495
|
+
> [`StrictBigintType<T, Then = T, Else = never>`](./ts/bigint/strict_bigint_type.ts#L15)
|
|
496
|
+
|
|
497
|
+
↪️ `parse`: if `T` is exactly `bigint`.
|
|
498
|
+
|
|
499
|
+
> [`IsStrictBigint<T, Then = true, Else = false>`](./ts/bigint/strict_bigint_type.ts#L33)
|
|
500
|
+
|
|
501
|
+
⭕ `predicate`: if `T` is exactly `bigint`.
|
|
502
|
+
|
|
503
|
+
> [`NotStrictBigintType<T, Then = T, Else = never>`](./ts/bigint/strict_bigint_type.ts#L47)
|
|
504
|
+
|
|
505
|
+
↪️ `parse`: if `T` is not exactly `bigint`.
|
|
506
|
+
|
|
507
|
+
> [`IsNotStrictBigint<T, Then = true, Else = false>`](./ts/bigint/strict_bigint_type.ts#L61)
|
|
508
|
+
|
|
509
|
+
⭕ `predicate`: if `T` is not exactly `bigint`.
|
|
510
|
+
|
|
511
|
+
### boolean
|
|
512
|
+
|
|
513
|
+
> [`BooleanType<T>`](./ts/boolean/readme.md#type-checking)
|
|
514
|
+
|
|
515
|
+
↪️ `parse`: `T === boolean`.
|
|
516
|
+
|
|
517
|
+
> [`IsBoolean<T>`](./ts/boolean/readme.md#type-checking)
|
|
518
|
+
|
|
519
|
+
⭕ `predicate`: `T === boolean`
|
|
520
|
+
|
|
521
|
+
> [`NotBooleanType<T>`](./ts/boolean/readme.md#type-checking)
|
|
522
|
+
|
|
523
|
+
↪️ `parse`: `T !== boolean`.
|
|
524
|
+
|
|
525
|
+
> [`IsNotBoolean<T>`](./ts/boolean/readme.md#type-checking)
|
|
526
|
+
|
|
527
|
+
⭕ `predicate`: `T !== boolean`
|
|
528
|
+
|
|
529
|
+
### function
|
|
530
|
+
|
|
531
|
+
> [`FunctionType<T>`](./ts/function/readme.md#type-checking)
|
|
532
|
+
|
|
533
|
+
↪️ `parse`: `T === function`.
|
|
534
|
+
|
|
535
|
+
> [`IsFunction<T>`](./ts/function/readme.md#type-checking)
|
|
536
|
+
|
|
537
|
+
⭕ `predicate`: `T === function`
|
|
538
|
+
|
|
539
|
+
> [`NotFunctionType<T>`](./ts/function/readme.md#type-checking)
|
|
540
|
+
|
|
541
|
+
↪️ `parse`: `T !== function`.
|
|
542
|
+
|
|
543
|
+
> [`IsNotFunction<T>`](./ts/function/readme.md#type-checking)
|
|
544
|
+
|
|
545
|
+
⭕ `predicate`: `T !== function`
|
|
546
|
+
|
|
547
|
+
> `AnyFunction<P, R>`
|
|
548
|
+
|
|
549
|
+
🔨 `utilities`: a generic type for any function
|
|
550
|
+
|
|
551
|
+
> `ExtractFunction<F>`
|
|
552
|
+
|
|
553
|
+
🔨 `utilities`: extract the function signature from a type `F`.
|
|
554
|
+
|
|
555
|
+
> `extractFunction(fn: F)`
|
|
556
|
+
|
|
557
|
+
🔨 `utilities`: adjust type of `fn` to its function signature only.
|
|
558
|
+
|
|
559
|
+
> `inspect<T>(value: T, inspector?: (v: T) => void)`
|
|
560
|
+
|
|
561
|
+
🔨 `utilities`: inspect a value and return it. Inspector defaults to `console.dir()`
|
|
562
|
+
|
|
563
|
+
### never
|
|
564
|
+
|
|
565
|
+
> [`NeverType<T>`](./ts/never/readme.md#type-checking)
|
|
566
|
+
|
|
567
|
+
↪️ `parse`: `T === never`.
|
|
568
|
+
|
|
569
|
+
> [`IsNever<T>`](./ts/never/readme.md#type-checking)
|
|
570
|
+
|
|
571
|
+
⭕ `predicate`: `T === never`
|
|
572
|
+
|
|
573
|
+
> [`NotNeverType<T>`](./ts/never/readme.md#type-checking)
|
|
574
|
+
|
|
575
|
+
↪️ `parse`: `T !== never`.
|
|
576
|
+
|
|
577
|
+
> [`IsNotNever<T>`](./ts/never/readme.md#type-checking)
|
|
578
|
+
|
|
579
|
+
⭕ `predicate`: `T !== never`
|
|
580
|
+
|
|
581
|
+
### null
|
|
582
|
+
|
|
583
|
+
> [`NullType<T>`](./ts/null/readme.md#type-checking)
|
|
584
|
+
|
|
585
|
+
↪️ `parse`: `T === null`.
|
|
586
|
+
|
|
587
|
+
> [`IsNull<T>`](./ts/null/readme.md#type-checking)
|
|
588
|
+
|
|
589
|
+
⭕ `predicate`: `T === null`
|
|
590
|
+
|
|
591
|
+
> [`NotNullType<T>`](./ts/null/readme.md#type-checking)
|
|
592
|
+
|
|
593
|
+
↪️ `parse`: `T !== null`.
|
|
594
|
+
|
|
595
|
+
> [`IsNotNull<T>`](./ts/null/readme.md#type-checking)
|
|
596
|
+
|
|
597
|
+
⭕ `predicate`: `T !== null`
|
|
598
|
+
|
|
599
|
+
### number
|
|
600
|
+
|
|
601
|
+
> [`NumberType<T, Then = N, Else = never>`](./ts/number/number_type.ts#L14)
|
|
602
|
+
|
|
603
|
+
↪️ `parse`: is the type `T` `number`.
|
|
604
|
+
|
|
605
|
+
> [`IsNumber<T, Then = true, Else = false>`](./ts/number/number_type.ts#L27)
|
|
606
|
+
|
|
607
|
+
⭕ `predicate`: is the type `T` `number`.
|
|
608
|
+
|
|
609
|
+
> [`NotNumberType<T, Then = T, Else = never>`](./ts/number/number_type.ts#L40)
|
|
610
|
+
|
|
611
|
+
↪️ `parse`: is the type `T` not `number`.
|
|
612
|
+
|
|
613
|
+
> [`IsNotNumber<T, Then = true, Else = false>`](./ts/number/number_type.ts#L53)
|
|
614
|
+
|
|
615
|
+
⭕ `predicate`: is the type `T` not `number`.
|
|
616
|
+
|
|
617
|
+
> [`StrictNumberType<T, Then = N, Else = never>`](./ts/number/strict_number_type.ts#L19)
|
|
618
|
+
|
|
619
|
+
↪️ `parse`: is the type `T` exactly `number`.
|
|
620
|
+
|
|
621
|
+
> [`IsStrictNumber<T, Then = true, Else = false>`](./ts/number/strict_number_type.ts#L41)
|
|
622
|
+
|
|
623
|
+
⭕ `predicate`: is the type `T` exactly `number`.
|
|
624
|
+
|
|
625
|
+
> [`NotStrictNumberType<T, Then = T, Else = never>`](./ts/number/strict_number_type.ts#L55)
|
|
626
|
+
|
|
627
|
+
↪️ `parse`: is the type `T` not exactly `number`.
|
|
628
|
+
|
|
629
|
+
> [`IsNotStrictNumber<T, Then = true, Else = false>`](./ts/number/strict_number_type.ts#L69)
|
|
630
|
+
|
|
631
|
+
⭕ `predicate`: is the type `T` not exactly `number`.
|
|
632
|
+
|
|
633
|
+
### numeric
|
|
634
|
+
|
|
635
|
+
> [`Numeric`](./ts/numeric/numeric_type.ts#L4)
|
|
636
|
+
|
|
637
|
+
📘 `definition`: `number | bigint`.
|
|
638
|
+
|
|
639
|
+
> [`Zero`](ts/numeric_plus/numeric_type.ts#L9)
|
|
640
|
+
|
|
641
|
+
📘 `definition`: `0 | 0n`
|
|
642
|
+
|
|
643
|
+
> [`Integer<N, Then = N, Else = never>`](./ts/numeric/integer.ts#L15)
|
|
644
|
+
|
|
645
|
+
↪️ `parse`: is integer.
|
|
646
|
+
|
|
647
|
+
> [`IsInteger<N, Then = true, Else = false>`](./ts/numeric/integer.ts#L32)
|
|
648
|
+
|
|
649
|
+
⭕ `predicate`: is integer.
|
|
650
|
+
|
|
651
|
+
> [`NotInteger<N, Then = N, Else = never>`](./ts/numeric/integer.ts#L45)
|
|
652
|
+
|
|
653
|
+
↪️ `parse`: is not integer.
|
|
654
|
+
|
|
655
|
+
> [`IsNotInteger<N, Then = true, Else = false>`](./ts/numeric/integer.ts#L60)
|
|
656
|
+
|
|
657
|
+
⭕ `predicate`: is not integer.
|
|
658
|
+
|
|
659
|
+
> [`IsWhole<N, Then = true, Else = false>`](./ts/numeric/integer.ts#L75)
|
|
660
|
+
|
|
661
|
+
💀⭕ `deprecated`, `predicate`: is integer. Use `IsInteger` instead.
|
|
662
|
+
|
|
663
|
+
> [`Negative<N, Then = N, Else = never>`](./ts/numeric/negative.ts#L19)
|
|
664
|
+
|
|
665
|
+
↪️ `parse`: is negative.
|
|
666
|
+
|
|
667
|
+
> [`IsNegative<N, Then = true, Else = false>`](./ts/numeric/negative.ts#L53)
|
|
668
|
+
|
|
669
|
+
⭕ `predicate`: is negative.
|
|
670
|
+
|
|
671
|
+
> [`NonNegative<N, Then = N, Else = never>`](./ts/numeric/negative.ts#L69)
|
|
672
|
+
|
|
673
|
+
↪️ `parse`: is not negative.
|
|
674
|
+
|
|
675
|
+
> [`IsNonNegative<N, Then = N, Else = never>`](./ts/numeric/negative.ts#L101)
|
|
676
|
+
|
|
677
|
+
⭕ `predicate`: is not negative.
|
|
678
|
+
|
|
679
|
+
> [`Positive<N, Then = N, Else = never>`](./ts/numeric/positive.ts#15)
|
|
680
|
+
|
|
681
|
+
↪️ `parse`: is positive.
|
|
682
|
+
|
|
683
|
+
> [`IsPositive<N, Then = true, Else = false>`](./ts/numeric/positive.ts#L36)
|
|
684
|
+
|
|
685
|
+
⭕ `predicate`: is positive.
|
|
686
|
+
|
|
687
|
+
> [`NotPositive<N, Then = N, Else = never>`](./ts/numeric/positive.ts#48)
|
|
688
|
+
|
|
689
|
+
↪️ `parse`: is not positive.
|
|
690
|
+
|
|
691
|
+
> [`IsNotPositive<N, Then = true, Else = false>`](./ts/numeric/positive.ts#L60)
|
|
692
|
+
|
|
693
|
+
⭕ `predicate`: is not positive.
|
|
694
|
+
|
|
695
|
+
### object
|
|
696
|
+
|
|
697
|
+
> `filterKey()`
|
|
698
|
+
|
|
699
|
+
🔨 `utilities`: type adjusted filter by key.
|
|
700
|
+
|
|
701
|
+
> `findKey()`
|
|
702
|
+
|
|
703
|
+
🔨 `utilities`: type adjusted find by key.
|
|
704
|
+
|
|
705
|
+
> `forEachKey()`
|
|
706
|
+
|
|
707
|
+
🔨 `utilities`: type adjusted for each by key.
|
|
708
|
+
|
|
709
|
+
> `HasKey<T, K>`
|
|
710
|
+
|
|
711
|
+
🔨 `utilities`: predicate type checking `T` has key `K`.
|
|
712
|
+
|
|
713
|
+
> `hasKey()`
|
|
714
|
+
|
|
715
|
+
🔨 `utilities`: function of `HasKey`.
|
|
716
|
+
|
|
717
|
+
> `IsRecord<T>`
|
|
718
|
+
|
|
719
|
+
🔨 `utilities`: `logical` predicate for `Record`.
|
|
720
|
+
|
|
721
|
+
> `KeysWithDiffTypes<A, B>`
|
|
722
|
+
|
|
723
|
+
🔨 `utilities`: gets the keys common in `A` and `B` but with different value type.
|
|
724
|
+
|
|
725
|
+
> `mapKey()`
|
|
726
|
+
|
|
727
|
+
🔨 `utilities`: type adjusted map by key.
|
|
728
|
+
|
|
729
|
+
> `RecordValue<R>`
|
|
730
|
+
|
|
731
|
+
🔨 `utilities`: gets the value type `T`from `Record<any, T>`
|
|
732
|
+
|
|
733
|
+
[video](https://www.youtube.com/watch?v=1J7xK6FUqPw).
|
|
734
|
+
|
|
735
|
+
> `reduceByKey()`
|
|
736
|
+
|
|
737
|
+
🔨 `utilities`: type adjusted reduce by key.
|
|
738
|
+
|
|
739
|
+
> `someKey()`
|
|
740
|
+
|
|
741
|
+
🔨 `utilities`: type adjusted some by key.
|
|
742
|
+
|
|
743
|
+
> `SpreadRecord<A, B>`
|
|
744
|
+
|
|
745
|
+
🔨 `utilities`: type for `{...a, ...b}` when both `a` and `b` are `Record`\
|
|
746
|
+
for array, just do `[...A, ...B]`.
|
|
747
|
+
|
|
748
|
+
### Promise
|
|
749
|
+
|
|
750
|
+
> `AwaitedProp<T, V>`
|
|
751
|
+
|
|
752
|
+
🔨 `utilities`: `Awaited` on specified props `P` in `T`.
|
|
753
|
+
|
|
754
|
+
> `isPromise<R>(subject: any)`
|
|
755
|
+
|
|
756
|
+
🔨 `utilities`: `isPromise()` type guard.
|
|
757
|
+
|
|
758
|
+
> `MaybePromise<T>`
|
|
759
|
+
|
|
760
|
+
🔨 `utilities`: Alias of `T | Promise<T>`.
|
|
761
|
+
|
|
762
|
+
> `PromiseValue<P>`
|
|
763
|
+
|
|
764
|
+
🔨 `utilities`: Gets the type within the Promise.
|
|
765
|
+
|
|
766
|
+
> `PromiseValueMerge<P1, P2, ...P9>`
|
|
767
|
+
|
|
768
|
+
🔨 `utilities`: Merge the values of multiple promises.
|
|
769
|
+
|
|
770
|
+
> `mapSeries()`
|
|
771
|
+
|
|
772
|
+
🔨 `utilities`: Similar to `bluebird.mapSeries()` but works with `async`/`await`.
|
|
773
|
+
|
|
774
|
+
> `transformMaybePromise(value, transformer)`
|
|
775
|
+
|
|
776
|
+
🔨 `utilities`: Apply the `transformer` to the `value`.\
|
|
777
|
+
It is also exported under `MaybePromise.transform()`.
|
|
778
|
+
|
|
779
|
+
### string
|
|
780
|
+
|
|
781
|
+
> [`StringType<T>`](ts/string/readme.md#type-checking)
|
|
782
|
+
|
|
783
|
+
↪️ `parse`: is `string`.
|
|
784
|
+
|
|
785
|
+
> [`IsString<T>`](ts/string/readme.md#type-checking)
|
|
786
|
+
|
|
787
|
+
⭕ `predicate`: is `string`.
|
|
788
|
+
|
|
789
|
+
> [`NotStringType<T>`](ts/string/readme.md#type-checking)
|
|
790
|
+
|
|
791
|
+
↪️ `parse`: is not `string`.
|
|
792
|
+
|
|
793
|
+
> [`IsNotString<T>`](ts/string/readme.md#type-checking)
|
|
794
|
+
|
|
795
|
+
⭕ `predicate`: is not `string`.
|
|
796
|
+
|
|
797
|
+
### symbol
|
|
798
|
+
|
|
799
|
+
> [`SymbolType<T>`](ts/symbol/readme.md#type-checking)
|
|
800
|
+
|
|
801
|
+
↪️ `parse`: is `symbol`.
|
|
802
|
+
|
|
803
|
+
> [`IsSymbol<T>`](ts/symbol/readme.md#type-checking)
|
|
804
|
+
|
|
805
|
+
⭕ `predicate`: is `symbol`.
|
|
806
|
+
|
|
807
|
+
> [`NotSymbolType<T>`](ts/symbol/readme.md#type-checking)
|
|
808
|
+
|
|
809
|
+
↪️ `parse`: is not `symbol`.
|
|
810
|
+
|
|
811
|
+
> [`IsNotSymbol<T>`](ts/symbol/readme.md#type-checking)
|
|
812
|
+
|
|
813
|
+
⭕ `predicate`: is not `symbol`.
|
|
814
|
+
|
|
815
|
+
### tuple
|
|
816
|
+
|
|
817
|
+
> [`TupleType<T>`](ts/tuple/readme.md#type-checking)
|
|
818
|
+
|
|
819
|
+
↪️ `parse`: is a tuple.
|
|
820
|
+
|
|
821
|
+
> [`IsTuple<T>`](ts/tuple/readme.md#type-checking)
|
|
822
|
+
|
|
823
|
+
⭕ `predicate`: is a tuple.
|
|
824
|
+
|
|
825
|
+
> [`NotTupleType<T>`](ts/tuple/readme.md#type-checking)
|
|
826
|
+
|
|
827
|
+
↪️ `parse`: is not a tuple.
|
|
828
|
+
|
|
829
|
+
> [`IsNotTuple<T>`](ts/tuple/readme.md#type-checking)
|
|
830
|
+
|
|
831
|
+
⭕ `predicate`: is not a tuple.
|
|
832
|
+
|
|
833
|
+
### undefined
|
|
834
|
+
|
|
835
|
+
> [`UndefinedType<T>`](./ts/undefined/readme.md#type-checking)
|
|
836
|
+
|
|
837
|
+
↪️ `parse`: `T === undefined`.
|
|
838
|
+
|
|
839
|
+
> [`IsUndefined<T>`](./ts/undefined/readme.md#type-checking)
|
|
840
|
+
|
|
841
|
+
⭕ `predicate`: `T === undefined`
|
|
842
|
+
|
|
843
|
+
> [`NotUndefinedType<T>`](./ts/undefined/readme.md#type-checking)
|
|
844
|
+
|
|
845
|
+
↪️ `parse`: `T !== undefined`.
|
|
846
|
+
|
|
847
|
+
> [`IsNotUndefined<T>`](./ts/undefined/readme.md#type-checking)
|
|
848
|
+
|
|
849
|
+
⭕ `predicate`: `T !== undefined`
|
|
850
|
+
|
|
851
|
+
### unknown
|
|
852
|
+
|
|
853
|
+
> [`UnknownType<T>`](./ts/unknown/readme.md#type-checking)
|
|
854
|
+
|
|
855
|
+
↪️ `parse`: `T === unknown`.
|
|
856
|
+
|
|
857
|
+
> [`IsUnknown<T>`](./ts/unknown/readme.md#type-checking)
|
|
858
|
+
|
|
859
|
+
⭕ `predicate`: `T === unknown`
|
|
860
|
+
|
|
861
|
+
> [`NotUnknownType<T>`](./ts/unknown/readme.md#type-checking)
|
|
862
|
+
|
|
863
|
+
↪️ `parse`: `T !== unknown`.
|
|
864
|
+
|
|
865
|
+
> [`IsNotUnknown<T>`](./ts/unknown/readme.md#type-checking)
|
|
866
|
+
|
|
867
|
+
⭕ `predicate`: `T !== unknown`
|
|
868
|
+
|
|
869
|
+
### void
|
|
870
|
+
|
|
871
|
+
> [`VoidType<T>`](./ts/void/readme.md#type-checking)
|
|
872
|
+
|
|
873
|
+
↪️ `parse`: `T === void`.
|
|
874
|
+
|
|
875
|
+
> [`IsVoid<T>`](./ts/void/readme.md#type-checking)
|
|
876
|
+
|
|
877
|
+
⭕ `predicate`: `T === void`
|
|
878
|
+
|
|
879
|
+
> [`NotVoidType<T>`](./ts/void/readme.md#type-checking)
|
|
880
|
+
|
|
881
|
+
↪️ `parse`: `T !== void`.
|
|
882
|
+
|
|
883
|
+
> [`IsNotVoid<T>`](./ts/void/readme.md#type-checking)
|
|
884
|
+
|
|
885
|
+
⭕ `predicate`: `T !== void`
|
|
886
|
+
|
|
887
|
+
## Constant Types
|
|
888
|
+
|
|
889
|
+
> `KeyTypes`
|
|
890
|
+
|
|
891
|
+
📘 `definition`: type of all keys.
|
|
892
|
+
|
|
893
|
+
> `PrimitiveTypes`
|
|
894
|
+
|
|
895
|
+
📘 `definition`: all primitive types, including `Function`, `symbol`, and `bigint`.
|
|
896
|
+
|
|
897
|
+
> `ComposableTypes`
|
|
898
|
+
|
|
899
|
+
📘 `definition`: Types that can contain custom properties. i.e. `object`, `array`, `function`.
|
|
900
|
+
|
|
901
|
+
> `NonComposableTypes`
|
|
902
|
+
|
|
903
|
+
📘 `definition`: Types that cannot contain custom properties. i.e. not composable.
|
|
904
|
+
|
|
905
|
+
## JSON Support
|
|
906
|
+
|
|
907
|
+
> `JSONPrimitive`
|
|
908
|
+
|
|
909
|
+
📘 `definition`: primitive types valid in JSON
|
|
910
|
+
|
|
911
|
+
> `JSONObject`
|
|
912
|
+
|
|
913
|
+
📘 `definition`: JSON object
|
|
914
|
+
|
|
915
|
+
> `JSONArray`
|
|
916
|
+
|
|
917
|
+
📘 `definition`: JSON array
|
|
918
|
+
|
|
919
|
+
> `JSONTypes`
|
|
920
|
+
|
|
921
|
+
📘 `definition`: all JSON compatible types.
|
|
922
|
+
|
|
923
|
+
> `JSONTypes.get<T>(obj, ...props)`
|
|
924
|
+
|
|
925
|
+
🔨 `utilities`: get a cast value in JSON
|
|
397
926
|
|
|
398
927
|
```ts
|
|
399
928
|
import { JSONTypes } from 'type-plus'
|
|
@@ -403,144 +932,303 @@ const someJson: JSONTypes = { a: { b: ['z', { c: 'miku' }]}}
|
|
|
403
932
|
JSONTypes.get<string>(someJson, 'a', 'b', 1, 'c') // miku
|
|
404
933
|
```
|
|
405
934
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
- `filterKey()`: type adjusted filter by key.
|
|
409
|
-
- `findKey()`: type adjusted find by key.
|
|
410
|
-
- `forEachKey()`: type adjusted for each by key.
|
|
411
|
-
- `HasKey<T, K>`: predicate type checking `T` has key `K`.
|
|
412
|
-
- `hasKey()`: function of `HasKey`.
|
|
413
|
-
- `IsRecord<T>`: `logical` predicate for `Record`.
|
|
414
|
-
- `KeysWithDiffTypes<A, B>`: gets the keys common in `A` and `B` but with different value type.
|
|
415
|
-
- `mapKey()`: type adjusted map by key.
|
|
416
|
-
- `RecordValue<R>`: gets the value type `T`from `Record<any, T>` [video](https://www.youtube.com/watch?v=1J7xK6FUqPw).
|
|
417
|
-
- `reduceByKey()`: type adjusted reduce by key.
|
|
418
|
-
- `someKey()`: type adjusted some by key.
|
|
419
|
-
- `SpreadRecord<A, B>`: type for `{...a, ...b}` when both `a` and `b` are `Record`\
|
|
420
|
-
for array, just do `[...A, ...B]`.
|
|
935
|
+
## Type manipulation
|
|
421
936
|
|
|
422
|
-
|
|
937
|
+
> `ANotB<A, B>`
|
|
423
938
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
939
|
+
🔨 `utilities`: get object with properties in `A` and not in `B`, including properties with a different value type.
|
|
940
|
+
|
|
941
|
+
> `BNotA<A, B>`
|
|
942
|
+
|
|
943
|
+
🔨 `utilities`: flip of `ANotB`
|
|
944
|
+
|
|
945
|
+
> `as<T>(subject)`
|
|
946
|
+
|
|
947
|
+
🔨 `utilities`: assert `subject` as `T`. Avoid ASI issues such as `;(x as T).abc`
|
|
948
|
+
|
|
949
|
+
> `asAny(subject)`
|
|
950
|
+
|
|
951
|
+
🔨 `utilities`: assert `subject` as `any`. Avoid ASI issue such as `;(x as any).abc`
|
|
952
|
+
|
|
953
|
+
> `EitherAnd<A, B, [C, D]>`
|
|
954
|
+
|
|
955
|
+
💀🔨 `deprecated`,`utilities`: Renamed to `EitherOrBoth`. combines 2 to 4 types as `A | B | (A & B)`.
|
|
956
|
+
|
|
957
|
+
This is useful for combining options.
|
|
958
|
+
|
|
959
|
+
> `EitherOrBoth<A, B, [C, D]>`
|
|
960
|
+
|
|
961
|
+
🔨 `utilities`: combines 2 to 4 types as `A | B | (A & B)`.
|
|
962
|
+
|
|
963
|
+
This is useful for combining options [video](https://youtu.be/jBxx03NT4Ik).
|
|
964
|
+
|
|
965
|
+
> `Except<T, K>`
|
|
966
|
+
|
|
967
|
+
💀🔨 `deprecated`,`utilities`: same as `Omit<T, K>`.
|
|
968
|
+
|
|
969
|
+
> `ExcludePropType<T, U>`
|
|
970
|
+
|
|
971
|
+
🔨 `utilities`: excludes type `U` from properties in `T`.
|
|
972
|
+
|
|
973
|
+
> `KeyofOptional<T>`
|
|
974
|
+
|
|
975
|
+
🔨 `utilities`: `keyof` that works with `Record<any, any> | undefined`.
|
|
976
|
+
|
|
977
|
+
> `KnownKeys<T>`
|
|
978
|
+
|
|
979
|
+
🔨 `utilities`: extract known (defined) keys from type `T`.
|
|
980
|
+
|
|
981
|
+
> `LeftJoin<A, B>`
|
|
982
|
+
|
|
983
|
+
🔨 `utilities`: left join `A` with `B`
|
|
984
|
+
|
|
985
|
+
> `NonNull<T>`
|
|
986
|
+
|
|
987
|
+
🔨 `utilities`: remove `null`
|
|
988
|
+
|
|
989
|
+
> `NonNullable<T>` (built-in)
|
|
990
|
+
|
|
991
|
+
🔨 `utilities`: adjust the type not to nullable
|
|
992
|
+
|
|
993
|
+
> `NonUndefined<T>`
|
|
994
|
+
|
|
995
|
+
🔨 `utilities`: remove `undefined`
|
|
996
|
+
|
|
997
|
+
> `Omit<T, K>`
|
|
998
|
+
|
|
999
|
+
🔨 `utilities`: From `T`, pick a set of properties whose keys are not in the union `K`. This is the opposite of `Pick<T, K>`.
|
|
1000
|
+
|
|
1001
|
+
> `OptionalKeys<T>`
|
|
1002
|
+
|
|
1003
|
+
🔨 `utilities`: gets keys of optional properties in `T`.
|
|
1004
|
+
|
|
1005
|
+
> `PartialExcept<T, U>`
|
|
1006
|
+
|
|
1007
|
+
💀🔨 `deprecated`,`utilities`: same as `PartialOmit<T, U>`.
|
|
1008
|
+
|
|
1009
|
+
> `PartialOmit<T, U>`
|
|
1010
|
+
|
|
1011
|
+
🔨 `utilities`: makes the properties not specified in `U` becomes optional.
|
|
1012
|
+
|
|
1013
|
+
> `PartialPick<T, U>`
|
|
1014
|
+
|
|
1015
|
+
🔨 `utilities`: makes the properties specified in `U` becomes optional.
|
|
1016
|
+
|
|
1017
|
+
> `Pick<T, K>`
|
|
1018
|
+
|
|
1019
|
+
🔨 `utilities`: pick properties `K` from `T`. Works with unions.
|
|
1020
|
+
|
|
1021
|
+
> `RecursivePartial<T>`
|
|
1022
|
+
|
|
1023
|
+
🔨 `utilities`: make type `T` optional recursively.
|
|
432
1024
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
1025
|
+
> `RecursiveRequired<T>`
|
|
1026
|
+
|
|
1027
|
+
🔨 `utilities`: make type `T` required recursively.
|
|
1028
|
+
|
|
1029
|
+
> `ReplaceProperty<T, K, V>`
|
|
1030
|
+
|
|
1031
|
+
🔨 `utilities`: replace property `K` in `T` with `V`.
|
|
1032
|
+
|
|
1033
|
+
> `RequiredKeys<T>`
|
|
1034
|
+
|
|
1035
|
+
🔨 `utilities`: gets keys of required properties in `T`.
|
|
1036
|
+
|
|
1037
|
+
> `RequiredPick<T, U>`
|
|
1038
|
+
|
|
1039
|
+
🔨 `utilities`: makes the properties specified in `U` become required.
|
|
1040
|
+
|
|
1041
|
+
> `RequiredExcept<T, U>`
|
|
1042
|
+
|
|
1043
|
+
🔨 `utilities`: makes the properties not specified in `U` become required.
|
|
1044
|
+
|
|
1045
|
+
> `RecursiveIntersect<T, U>`
|
|
1046
|
+
|
|
1047
|
+
🔨 `utilities`: intersect type `U` onto `T` recursively.
|
|
1048
|
+
|
|
1049
|
+
> `ValueOf<T>`
|
|
1050
|
+
|
|
1051
|
+
🔨 `utilities`: type of the value of the properties of `T`.
|
|
1052
|
+
|
|
1053
|
+
> `Widen<T>`
|
|
1054
|
+
|
|
1055
|
+
🔨 `utilities`: widen literal types.
|
|
1056
|
+
|
|
1057
|
+
PropType
|
|
1058
|
+
|
|
1059
|
+
💀 ...no helper type for this. Just do `YourType['propName']`.
|
|
1060
|
+
|
|
1061
|
+
## Type Predicates
|
|
466
1062
|
|
|
467
1063
|
Type predicates are type alias that returns `true` or `false`.
|
|
468
1064
|
They can be used to compose complex types.
|
|
469
1065
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
1066
|
+
> `HasKey<T, K>`
|
|
1067
|
+
|
|
1068
|
+
🔨 `utilities`: predicate type checking `T` has key `K`.
|
|
1069
|
+
|
|
1070
|
+
> `IsAny<T>`
|
|
1071
|
+
|
|
1072
|
+
🔨 `utilities`: `T === any` (updated to impl: [expect-type]).
|
|
1073
|
+
|
|
1074
|
+
> `IsBoolean<T>`
|
|
1075
|
+
|
|
1076
|
+
🔨 `utilities`: check for `boolean`, but not for `true` nor `false`.
|
|
1077
|
+
|
|
1078
|
+
> `IsDisjoint<A, B>`
|
|
1079
|
+
|
|
1080
|
+
🔨 `utilities`: is `A` and `B` is a disjoint set.
|
|
1081
|
+
|
|
1082
|
+
> `IsEmptyObject<T>`
|
|
1083
|
+
|
|
1084
|
+
🔨 `utilities`: is `T === {}`.
|
|
1085
|
+
|
|
1086
|
+
> `IsLiteral<T>`
|
|
1087
|
+
|
|
1088
|
+
🔨 `utilities`: is `T` a literal type (literal string or number).
|
|
1089
|
+
|
|
1090
|
+
### Logical
|
|
1091
|
+
|
|
1092
|
+
> `If<Condition, Then = true, Else = false>`
|
|
476
1093
|
|
|
477
|
-
|
|
1094
|
+
🔨 `utilities`: if statement
|
|
478
1095
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
1096
|
+
> `And<A, B, Then = true, Else = false>`
|
|
1097
|
+
|
|
1098
|
+
🔨 `utilities`: logical `AND`
|
|
1099
|
+
|
|
1100
|
+
> `Or<A, B, Then = true, Else = false>`
|
|
1101
|
+
|
|
1102
|
+
🔨 `utilities`: logical `OR`
|
|
1103
|
+
|
|
1104
|
+
> `Xor<A, B, Then = true, Else = false>`
|
|
1105
|
+
|
|
1106
|
+
🔨 `utilities`: logical `XOR`
|
|
1107
|
+
|
|
1108
|
+
> `Not<X, Then = true, Else = false>`
|
|
1109
|
+
|
|
1110
|
+
🔨 `utilities`: logical `NOT`
|
|
484
1111
|
|
|
485
1112
|
Note that these types work correctly with the `boolean` type.
|
|
486
1113
|
e.g.:
|
|
487
1114
|
|
|
488
|
-
|
|
489
|
-
|
|
1115
|
+
```ts
|
|
1116
|
+
type R = And<boolean, true> // boolean
|
|
1117
|
+
type R = Not<boolean> // boolean`
|
|
1118
|
+
```
|
|
490
1119
|
|
|
491
1120
|
There is a problem with generic distribution: <https://github.com/microsoft/TypeScript/issues/41053>
|
|
492
1121
|
So you may encounter some weird behavior if your logic is complex.
|
|
493
1122
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
1123
|
+
## Math
|
|
1124
|
+
|
|
1125
|
+
The math types in `type-plus` works with most numeric types.
|
|
1126
|
+
|
|
1127
|
+
It works with `number` and `bigint`, positive and negative number, including floating point numbers.
|
|
1128
|
+
|
|
1129
|
+
It will cast the type between `number` and `bigint` if needed.
|
|
1130
|
+
|
|
1131
|
+
> `Abs<N, Fail = never>`
|
|
1132
|
+
|
|
1133
|
+
🔨 `utilities`: `Abs(N)`.
|
|
1134
|
+
|
|
1135
|
+
> `Max<A, B, Fail = never>`
|
|
1136
|
+
|
|
1137
|
+
🔨 `utilities`: `max(A, B)`
|
|
1138
|
+
|
|
1139
|
+
> `GreaterThan<A, B>`
|
|
1140
|
+
|
|
1141
|
+
🔨 `utilities`: `A > B`.
|
|
1142
|
+
|
|
1143
|
+
> `Add<A, B>`
|
|
1144
|
+
|
|
1145
|
+
🔨 `utilities`: `A + B`.
|
|
1146
|
+
|
|
1147
|
+
> `Subtract<A, B>`
|
|
1148
|
+
|
|
1149
|
+
🔨 `utilities`: `A > B`.
|
|
1150
|
+
|
|
1151
|
+
> `Increment<A>`
|
|
1152
|
+
|
|
1153
|
+
🔨 `utilities`: alias of `Add<A, 1>`.
|
|
1154
|
+
|
|
1155
|
+
> `Decrement<A>`
|
|
1156
|
+
|
|
1157
|
+
🔨 `utilities`: alias of `Subtract<A, 1>`.
|
|
1158
|
+
|
|
1159
|
+
> `Multiply<A, B`
|
|
1160
|
+
|
|
1161
|
+
🔨 `utilities`: `A * B`.
|
|
1162
|
+
|
|
1163
|
+
## Utility Functions
|
|
1164
|
+
|
|
1165
|
+
> `amend(subject)...`
|
|
1166
|
+
|
|
1167
|
+
🔨 `utilities`: amend subject as union or intersect of `T`.
|
|
1168
|
+
|
|
1169
|
+
> `facade(subject, ...props)`
|
|
1170
|
+
|
|
1171
|
+
🔨 `utilities`: create a facade of `subject`.
|
|
1172
|
+
|
|
1173
|
+
> `getField(subject, key, defaultValue)`
|
|
1174
|
+
|
|
1175
|
+
🔨 `utilities`: get a field from a subject. Works against nullable and optional subject.
|
|
1176
|
+
|
|
1177
|
+
> `hasKey()`
|
|
1178
|
+
|
|
1179
|
+
🔨 `utilities`: function of `HasKey`.
|
|
1180
|
+
|
|
1181
|
+
> `hasProperty(value, prop)`
|
|
1182
|
+
|
|
1183
|
+
🔨 `utilities`: assert `value` has property `prop`. This will pick the correct union type.
|
|
1184
|
+
|
|
1185
|
+
> `isConstructor(subject)`
|
|
1186
|
+
|
|
1187
|
+
🔨 `utilities`: type guard `subject` is a constructor.
|
|
1188
|
+
|
|
1189
|
+
> `isSystemError(code, err)`
|
|
1190
|
+
|
|
1191
|
+
🔨 `utilities`: type guard `err` with NodeJS error code.
|
|
1192
|
+
|
|
1193
|
+
> `omit(obj, ...props)`
|
|
1194
|
+
|
|
1195
|
+
🔨 `utilities`: omit properties from `obj`.
|
|
1196
|
+
|
|
1197
|
+
> `pick(obj, ...props)`
|
|
1198
|
+
|
|
1199
|
+
🔨 `utilities`: pick properties from `obj`.
|
|
1200
|
+
|
|
1201
|
+
> `record<K, V>(value?)`
|
|
1202
|
+
|
|
1203
|
+
🔨 `utilities`: create a `Record<K, V>` without extra object prototype.
|
|
1204
|
+
|
|
1205
|
+
> `record<R>(value?)`
|
|
1206
|
+
|
|
1207
|
+
🔨 `utilities`: create a record `R` (e.g. `{ a: number }`) without extra object prototype.
|
|
1208
|
+
|
|
1209
|
+
> `required(...)`
|
|
1210
|
+
|
|
1211
|
+
🔨 `utilities`: merge options and remove `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
1212
|
+
|
|
1213
|
+
> `requiredDeep(...)`
|
|
1214
|
+
|
|
1215
|
+
🔨 `utilities`: merge options deeply and remove `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
1216
|
+
|
|
1217
|
+
> `split(target, ...splitters)`
|
|
1218
|
+
|
|
1219
|
+
🔨 `utilities`: split one object into multiple objects.
|
|
1220
|
+
|
|
1221
|
+
> `stub<T>(value)`
|
|
1222
|
+
|
|
1223
|
+
🔨 `utilities`: stub a particular type `T`.
|
|
1224
|
+
|
|
1225
|
+
> `stub.build<T>(init?)`
|
|
1226
|
+
|
|
1227
|
+
🔨 `utilities`: build a stub for particular type `T`.
|
|
1228
|
+
|
|
1229
|
+
> `typeOverrideIncompatible<T>()`
|
|
1230
|
+
|
|
1231
|
+
🔨 `utilities`: override only the incompatible portion between two types.
|
|
544
1232
|
|
|
545
1233
|
```ts
|
|
546
1234
|
type A = {
|
|
@@ -560,6 +1248,26 @@ const source = {
|
|
|
560
1248
|
overrider(source, { foo: !!source.foo })
|
|
561
1249
|
```
|
|
562
1250
|
|
|
1251
|
+
> `unpartial()`
|
|
1252
|
+
|
|
1253
|
+
🔨 `utilities`: merge options and remove `Partial<T>` values. From [`unpartial`](https://github.com/unional/unpartial)
|
|
1254
|
+
|
|
1255
|
+
> `context()`
|
|
1256
|
+
|
|
1257
|
+
🔨 `utilities`: a context builder.
|
|
1258
|
+
|
|
1259
|
+
This is useful to build context for functional programming.
|
|
1260
|
+
It is a sync version of the `AsyncContext` from [async-fp](https://unional/async-fp).
|
|
1261
|
+
|
|
1262
|
+
```ts
|
|
1263
|
+
import { context } from 'type-plus'
|
|
1264
|
+
|
|
1265
|
+
// { a: 1, b: 2 }
|
|
1266
|
+
const ctx = context({ a: 1 })
|
|
1267
|
+
.extend(c => ({ b: c.a + 1 }))
|
|
1268
|
+
.build()
|
|
1269
|
+
```
|
|
1270
|
+
|
|
563
1271
|
## Nominal Types
|
|
564
1272
|
|
|
565
1273
|
The TypeScript type system is structural.
|
|
@@ -610,7 +1318,9 @@ but `Flavor` of the same name cannot be assigned to `Brand`.
|
|
|
610
1318
|
|
|
611
1319
|
`nominalMatch(a, b)`:
|
|
612
1320
|
|
|
613
|
-
`
|
|
1321
|
+
🔨 `utilities`: compare if the two values are nominally equal.
|
|
1322
|
+
|
|
1323
|
+
Works with both `Brand` and `Flavor`.
|
|
614
1324
|
|
|
615
1325
|
```ts
|
|
616
1326
|
const b1 = brand('x', 1)
|
|
@@ -619,32 +1329,15 @@ const b2 = brand('y', 1)
|
|
|
619
1329
|
nominalMatch(b1, b2) // false
|
|
620
1330
|
```
|
|
621
1331
|
|
|
622
|
-
## Function Utilties
|
|
623
|
-
|
|
624
|
-
- `AnyFunction<P, R>`: a generic type for any function
|
|
625
|
-
- `ExtractFunction<F>`: extract the function signature from a type `F`.
|
|
626
|
-
- `extractFunction(fn: F)`: adjust type of `fn` to its function signature only.
|
|
627
|
-
- `inspect<T>(value: T, inspector?: (v: T) => void)`: inspect a value and return it.\
|
|
628
|
-
Inspector defaults to `console.dir()`
|
|
629
|
-
|
|
630
1332
|
## Functional Types
|
|
631
1333
|
|
|
632
|
-
|
|
633
|
-
- `compose(...fns): F`: compose functions
|
|
1334
|
+
> `ChainFn<T>: T`
|
|
634
1335
|
|
|
635
|
-
|
|
1336
|
+
🔨 `utilities`: chain function that returns the input type.
|
|
636
1337
|
|
|
637
|
-
|
|
638
|
-
It is a sync version of the `AsyncContext` from [async-fp](https://unional/async-fp).
|
|
1338
|
+
> `compose(...fns): F`
|
|
639
1339
|
|
|
640
|
-
|
|
641
|
-
import { context } from 'type-plus'
|
|
642
|
-
|
|
643
|
-
// { a: 1, b: 2 }
|
|
644
|
-
const ctx = context({ a: 1 })
|
|
645
|
-
.extend(c => ({ b: c.a + 1 }))
|
|
646
|
-
.build()
|
|
647
|
-
```
|
|
1340
|
+
🔨 `utilities`: compose functions
|
|
648
1341
|
|
|
649
1342
|
## Attribution
|
|
650
1343
|
|
|
@@ -652,6 +1345,10 @@ Some code in this library is created by other people in the TypeScript community
|
|
|
652
1345
|
I'm merely adding them in and maybe making some adjustments.
|
|
653
1346
|
Whenever possible, I add attribution to the person who created those **codes** in the file.
|
|
654
1347
|
|
|
1348
|
+
## Useful Tips
|
|
1349
|
+
|
|
1350
|
+
> <https://github.com/microsoft/TypeScript/wiki/Performance>
|
|
1351
|
+
|
|
655
1352
|
## Similar projects
|
|
656
1353
|
|
|
657
1354
|
- [expect-type]: Compile-time tests for types
|
|
@@ -694,7 +1391,6 @@ test results immediately as you type, and see the results in
|
|
|
694
1391
|
your editor right next to your code.
|
|
695
1392
|
|
|
696
1393
|
[@gcanti]: https://github.com/gcanti
|
|
697
|
-
[assertion_function]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
698
1394
|
[codecov_image]: https://codecov.io/gh/unional/type-plus/branch/master/graph/badge.svg
|
|
699
1395
|
[codecov_url]: https://codecov.io/gh/unional/type-plus
|
|
700
1396
|
[downloads_image]: https://img.shields.io/npm/dm/type-plus.svg?style=flat
|
|
@@ -708,7 +1404,6 @@ your editor right next to your code.
|
|
|
708
1404
|
[ts-essentials]: https://github.com/ts-essentials/ts-essentials
|
|
709
1405
|
[ts-expect]: https://github.com/TypeStrong/ts-expect
|
|
710
1406
|
[ts-toolbelt]: https://github.com/millsp/ts-toolbelt
|
|
711
|
-
[type_guard]: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
|
|
712
1407
|
[type-fest]: https://github.com/sindresorhus/type-fest
|
|
713
1408
|
[type-zoo]: https://github.com/pelotom/type-zoo
|
|
714
1409
|
[typelevel-ts]: https://github.com/gcanti/typelevel-ts
|
|
@@ -721,3 +1416,5 @@ your editor right next to your code.
|
|
|
721
1416
|
[wallaby_image]: https://img.shields.io/badge/wallaby.js-powered-blue.svg?style=flat&logo=github
|
|
722
1417
|
[wallaby_image_lg]: https://img.shields.io/badge/wallaby.js-powered-blue.svg?style=for-the-badge&logo=github
|
|
723
1418
|
[wallaby_url]: https://wallabyjs.com/oss/
|
|
1419
|
+
[assertion_functions]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
|
|
1420
|
+
[type_guard]: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
|