inferred-types 0.36.4 → 0.37.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.
Files changed (280) hide show
  1. package/README.md +1 -1
  2. package/dist/{index.mjs → index.js} +0 -0
  3. package/package.json +15 -21
  4. package/.eslintrc +0 -77
  5. package/.github/workflows/main.yml +0 -34
  6. package/.github/workflows/other.yml +0 -15
  7. package/.nvmrc +0 -1
  8. package/.prettierrc.js +0 -3
  9. package/.vscode/launch.json +0 -27
  10. package/.vscode/settings.json +0 -19
  11. package/devops/build.js +0 -243
  12. package/docs/builder-overview.md +0 -45
  13. package/docs/builder.md +0 -94
  14. package/src/errors/ReadOnlyViolation.ts +0 -3
  15. package/src/errors/index.ts +0 -12
  16. package/src/index.ts +0 -14
  17. package/src/runtime/README.md +0 -3
  18. package/src/runtime/api/api.ts +0 -10
  19. package/src/runtime/api/index.ts +0 -12
  20. package/src/runtime/builders/Model.ts +0 -25
  21. package/src/runtime/builders/url.ts +0 -15
  22. package/src/runtime/combinators/and.ts +0 -15
  23. package/src/runtime/combinators/filter.ts +0 -267
  24. package/src/runtime/combinators/index.ts +0 -4
  25. package/src/runtime/combinators/not.ts +0 -15
  26. package/src/runtime/combinators/or.ts +0 -5
  27. package/src/runtime/createFnWithProps.ts +0 -37
  28. package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
  29. package/src/runtime/dictionary/defineProperties.ts +0 -35
  30. package/src/runtime/dictionary/dictArr.ts +0 -69
  31. package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
  32. package/src/runtime/dictionary/entries.ts +0 -33
  33. package/src/runtime/dictionary/index.ts +0 -21
  34. package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
  35. package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
  36. package/src/runtime/dictionary/kv/index.ts +0 -15
  37. package/src/runtime/dictionary/kv/kv.ts +0 -18
  38. package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
  39. package/src/runtime/dictionary/mapTo.ts +0 -206
  40. package/src/runtime/dictionary/mapValues.ts +0 -23
  41. package/src/runtime/dictionary/merge.ts +0 -36
  42. package/src/runtime/dictionary/strArrayToDict.ts +0 -12
  43. package/src/runtime/index.ts +0 -23
  44. package/src/runtime/keys.ts +0 -16
  45. package/src/runtime/lists/asArray.ts +0 -38
  46. package/src/runtime/lists/createConverter.ts +0 -62
  47. package/src/runtime/lists/groupBy.ts +0 -15
  48. package/src/runtime/lists/index.ts +0 -15
  49. package/src/runtime/literals/ExplicitFunction.ts +0 -10
  50. package/src/runtime/literals/Suggest.ts +0 -19
  51. package/src/runtime/literals/arrayToObject.ts +0 -78
  52. package/src/runtime/literals/box.ts +0 -98
  53. package/src/runtime/literals/defineType.ts +0 -20
  54. package/src/runtime/literals/ensureLeading.ts +0 -17
  55. package/src/runtime/literals/ensureTrailing.ts +0 -17
  56. package/src/runtime/literals/identity.ts +0 -12
  57. package/src/runtime/literals/index.ts +0 -23
  58. package/src/runtime/literals/literal.ts +0 -48
  59. package/src/runtime/literals/pathJoin.ts +0 -33
  60. package/src/runtime/literals/stripLeading.ts +0 -15
  61. package/src/runtime/literals/stripTrailing.ts +0 -15
  62. package/src/runtime/literals/wide.ts +0 -13
  63. package/src/runtime/ruleset.ts +0 -42
  64. package/src/runtime/runtime/README.md +0 -3
  65. package/src/runtime/runtime/condition.ts +0 -13
  66. package/src/runtime/runtime/index.ts +0 -16
  67. package/src/runtime/runtime/type.ts +0 -127
  68. package/src/runtime/runtime/withValue.ts +0 -39
  69. package/src/runtime/state/Configurator.ts +0 -76
  70. package/src/runtime/state/FluentConfigurator.ts +0 -49
  71. package/src/runtime/state/index.ts +0 -13
  72. package/src/runtime/type-checks/ifSameType.ts +0 -20
  73. package/src/runtime/type-checks/ifTypeOf.ts +0 -124
  74. package/src/runtime/type-checks/index.ts +0 -24
  75. package/src/runtime/type-checks/isArray.ts +0 -34
  76. package/src/runtime/type-checks/isBoolean.ts +0 -24
  77. package/src/runtime/type-checks/isFalse.ts +0 -29
  78. package/src/runtime/type-checks/isFunction.ts +0 -26
  79. package/src/runtime/type-checks/isNull.ts +0 -26
  80. package/src/runtime/type-checks/isNumber.ts +0 -20
  81. package/src/runtime/type-checks/isObject.ts +0 -22
  82. package/src/runtime/type-checks/isString.ts +0 -34
  83. package/src/runtime/type-checks/isSymbol.ts +0 -3
  84. package/src/runtime/type-checks/isTrue.ts +0 -31
  85. package/src/runtime/type-checks/isUndefined.ts +0 -33
  86. package/src/runtime/type-checks/startsWith.ts +0 -107
  87. package/src/runtime/valueTypes.ts +0 -48
  88. package/src/types/Api.ts +0 -16
  89. package/src/types/Constructor.ts +0 -5
  90. package/src/types/EnumValues.ts +0 -14
  91. package/src/types/ExpandRecursively.ts +0 -12
  92. package/src/types/FunctionType.ts +0 -19
  93. package/src/types/If.ts +0 -10
  94. package/src/types/Include.ts +0 -18
  95. package/src/types/KeyedRecord.ts +0 -21
  96. package/src/types/Keys.ts +0 -26
  97. package/src/types/Length.ts +0 -8
  98. package/src/types/Mutable.ts +0 -8
  99. package/src/types/Narrowable.ts +0 -5
  100. package/src/types/Not.ts +0 -13
  101. package/src/types/Numeric.ts +0 -20
  102. package/src/types/Opaque.ts +0 -11
  103. package/src/types/README.md +0 -3
  104. package/src/types/Retain.ts +0 -16
  105. package/src/types/SimplifyObject.ts +0 -12
  106. package/src/types/Transformer.ts +0 -15
  107. package/src/types/TypeGuard.ts +0 -7
  108. package/src/types/Where.ts +0 -40
  109. package/src/types/alphabetic/AllCaps.ts +0 -15
  110. package/src/types/alphabetic/CamelCase.ts +0 -3
  111. package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
  112. package/src/types/alphabetic/CapitalizeWords.ts +0 -9
  113. package/src/types/alphabetic/Cardinality.ts +0 -80
  114. package/src/types/alphabetic/DashToSnake.ts +0 -3
  115. package/src/types/alphabetic/DashUppercase.ts +0 -19
  116. package/src/types/alphabetic/Dasherize.ts +0 -23
  117. package/src/types/alphabetic/EnsureLeading.ts +0 -24
  118. package/src/types/alphabetic/EnsureTrailing.ts +0 -24
  119. package/src/types/alphabetic/HasUppercase.ts +0 -16
  120. package/src/types/alphabetic/IsCapitalized.ts +0 -18
  121. package/src/types/alphabetic/KebabCase.ts +0 -13
  122. package/src/types/alphabetic/LowerAllCaps.ts +0 -5
  123. package/src/types/alphabetic/PascalCase.ts +0 -29
  124. package/src/types/alphabetic/PathJoin.ts +0 -54
  125. package/src/types/alphabetic/Pluralize.ts +0 -112
  126. package/src/types/alphabetic/SnakeCase.ts +0 -27
  127. package/src/types/alphabetic/StripLeading.ts +0 -23
  128. package/src/types/alphabetic/StripTrailing.ts +0 -23
  129. package/src/types/alphabetic/Url.ts +0 -29
  130. package/src/types/alphabetic/alpha-characters.ts +0 -81
  131. package/src/types/alphabetic/index.ts +0 -32
  132. package/src/types/append-types.ts +0 -10
  133. package/src/types/boolean-logic/EndsWith.ts +0 -40
  134. package/src/types/boolean-logic/Extends.ts +0 -22
  135. package/src/types/boolean-logic/HasParameters.ts +0 -21
  136. package/src/types/boolean-logic/Includes.ts +0 -33
  137. package/src/types/boolean-logic/IsLiteral.ts +0 -101
  138. package/src/types/boolean-logic/IsScalar.ts +0 -20
  139. package/src/types/boolean-logic/IsUndefined.ts +0 -20
  140. package/src/types/boolean-logic/Or.ts +0 -12
  141. package/src/types/boolean-logic/StartsWith.ts +0 -42
  142. package/src/types/boolean-logic/TypeDefault.ts +0 -58
  143. package/src/types/boolean-logic/array.ts +0 -57
  144. package/src/types/boolean-logic/boolean.ts +0 -84
  145. package/src/types/boolean-logic/equivalency.ts +0 -15
  146. package/src/types/boolean-logic/index.ts +0 -14
  147. package/src/types/boolean-logic/object.ts +0 -30
  148. package/src/types/boolean-logic/string.ts +0 -21
  149. package/src/types/dictionary/DictChangeValue.ts +0 -34
  150. package/src/types/dictionary/DictPartialApplication.ts +0 -30
  151. package/src/types/dictionary/DictPrependWithFn.ts +0 -23
  152. package/src/types/dictionary/DictReturnValues.ts +0 -27
  153. package/src/types/dictionary/Get.ts +0 -14
  154. package/src/types/dictionary/MapTo.ts +0 -428
  155. package/src/types/dictionary/MutableProps.ts +0 -19
  156. package/src/types/dictionary/RequireProps.ts +0 -15
  157. package/src/types/dictionary/SameKeys.ts +0 -11
  158. package/src/types/dictionary/index.ts +0 -21
  159. package/src/types/dictionary/props.ts +0 -145
  160. package/src/types/fluent/fluent.ts +0 -61
  161. package/src/types/fluent/index.ts +0 -12
  162. package/src/types/functions/FinalReturn.ts +0 -12
  163. package/src/types/functions/LogicFunction.ts +0 -4
  164. package/src/types/functions/index.ts +0 -13
  165. package/src/types/index.ts +0 -49
  166. package/src/types/kv/DictFromKv.ts +0 -3
  167. package/src/types/kv/KeyValue.ts +0 -12
  168. package/src/types/kv/KvFrom.ts +0 -8
  169. package/src/types/kv/KvTuple.ts +0 -14
  170. package/src/types/kv/index.ts +0 -15
  171. package/src/types/lists/AfterFirst.ts +0 -10
  172. package/src/types/lists/ConvertAndMap.ts +0 -151
  173. package/src/types/lists/FilterTuple.ts +0 -20
  174. package/src/types/lists/First.ts +0 -8
  175. package/src/types/lists/FirstString.ts +0 -4
  176. package/src/types/lists/Split.ts +0 -21
  177. package/src/types/lists/UniqueForProp.ts +0 -18
  178. package/src/types/lists/index.ts +0 -18
  179. package/src/types/literal-unions/OptRequired.ts +0 -4
  180. package/src/types/literal-unions/index.ts +0 -1
  181. package/src/types/maybe.ts +0 -9
  182. package/src/types/ruleset-types.ts +0 -76
  183. package/src/types/runtime.ts +0 -39
  184. package/src/types/string-literals/Break.ts +0 -22
  185. package/src/types/string-literals/Concat.ts +0 -9
  186. package/src/types/string-literals/LeftWhitespace.ts +0 -13
  187. package/src/types/string-literals/Replace.ts +0 -17
  188. package/src/types/string-literals/RightWhitespace.ts +0 -13
  189. package/src/types/string-literals/StringLength.ts +0 -34
  190. package/src/types/string-literals/Trim.ts +0 -15
  191. package/src/types/string-literals/TrimLeft.ts +0 -14
  192. package/src/types/string-literals/TrimRight.ts +0 -14
  193. package/src/types/string-literals/form-fields.ts +0 -15
  194. package/src/types/string-literals/index.ts +0 -21
  195. package/src/types/tuples/DictArray.ts +0 -21
  196. package/src/types/tuples/FirstKey.ts +0 -10
  197. package/src/types/tuples/FirstKeyValue.ts +0 -9
  198. package/src/types/tuples/FirstOfEach.ts +0 -13
  199. package/src/types/tuples/FromDictArray.ts +0 -14
  200. package/src/types/tuples/SecondOfEach.ts +0 -13
  201. package/src/types/tuples/index.ts +0 -17
  202. package/src/types/type-conversion/TupleToUnion.ts +0 -9
  203. package/src/types/type-conversion/UnionToIntersection.ts +0 -9
  204. package/src/types/type-conversion/UnionToTuple.ts +0 -20
  205. package/src/types/type-conversion/Widen.ts +0 -22
  206. package/src/types/type-conversion/index.ts +0 -16
  207. package/src/types/type-testing.ts +0 -14
  208. package/tests/CamelCase-spec.ts +0 -20
  209. package/tests/Configurator-spec.hold +0 -106
  210. package/tests/ExplicitFunction-spec.ts +0 -50
  211. package/tests/IncludeAndRetain-spec.ts +0 -67
  212. package/tests/Includes-spec.ts +0 -36
  213. package/tests/KebabCase-spec.ts +0 -21
  214. package/tests/PascalCase-spec.ts +0 -22
  215. package/tests/Pluralize-spec.ts +0 -23
  216. package/tests/SnakeCase-spec.ts +0 -21
  217. package/tests/Where.spec.ts +0 -38
  218. package/tests/arrayToKeyLookup-spec.ts +0 -17
  219. package/tests/arrayToObject-spec.ts +0 -115
  220. package/tests/boolean-logic/Contains.test.ts +0 -55
  221. package/tests/boolean-logic/HasParameters.ts +0 -29
  222. package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
  223. package/tests/boolean-logic/boolean.spec.ts +0 -21
  224. package/tests/boolean-logic/filter.spec.ts +0 -52
  225. package/tests/constructor.spec.ts +0 -42
  226. package/tests/createFnWithProps.spec.ts +0 -14
  227. package/tests/data/SimpleTable.hold +0 -21
  228. package/tests/data/index.ts +0 -12
  229. package/tests/data/playlist.hold +0 -25
  230. package/tests/data/song.hold +0 -23
  231. package/tests/defineType-spec.ts +0 -57
  232. package/tests/dictionary/DictChangeValue.test.ts +0 -30
  233. package/tests/dictionary/DictPartialApplication.test.ts +0 -43
  234. package/tests/dictionary/DictReturnValues.test.ts +0 -36
  235. package/tests/dictionary/Get.spec.ts +0 -28
  236. package/tests/dictionary/IntersectingKeys.test.ts +0 -42
  237. package/tests/dictionary/MutableProps.test.ts +0 -30
  238. package/tests/dictionary/OptionalKeys.test.ts +0 -24
  239. package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
  240. package/tests/dictionary/RequireProps.test.ts +0 -21
  241. package/tests/dictionary/RequiredKeys.test.ts +0 -53
  242. package/tests/dictionary/TypeDefault.test.ts +0 -76
  243. package/tests/dictionary/mapTo.test.ts +0 -388
  244. package/tests/dictionary/merge.test.ts +0 -41
  245. package/tests/dictionaryTransform-spec.ts +0 -280
  246. package/tests/ifTypeOf-spec.ts +0 -191
  247. package/tests/kv/KeyValue-spec.ts +0 -22
  248. package/tests/kv/SameKeys-spec.ts +0 -35
  249. package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
  250. package/tests/kv/entries-spec.ts +0 -65
  251. package/tests/kv/keys.spec.ts +0 -66
  252. package/tests/kv/kv-spec.ts +0 -20
  253. package/tests/lists/First.test.ts +0 -43
  254. package/tests/lists/Length.test.ts +0 -19
  255. package/tests/lists/Split.test.ts +0 -29
  256. package/tests/lists/UniqueForProp.spec.ts +0 -59
  257. package/tests/lists/asArray.test.ts +0 -109
  258. package/tests/lists/dictArr.test.ts +0 -110
  259. package/tests/literal-spec.ts +0 -82
  260. package/tests/literals/AllCaps.spec.ts +0 -33
  261. package/tests/literals/CamelCase.spec.ts +0 -109
  262. package/tests/literals/Dasherize.spec.ts +0 -107
  263. package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
  264. package/tests/literals/HasUppercase.spec.ts +0 -33
  265. package/tests/literals/PascalCase.spec.ts +0 -109
  266. package/tests/literals/PathJoin.test.ts +0 -111
  267. package/tests/literals/SnakeCase.spec.ts +0 -109
  268. package/tests/literals/box.test.ts +0 -85
  269. package/tests/literals/whitespace-capture.spec.ts +0 -60
  270. package/tests/mapValues-spec.ts +0 -50
  271. package/tests/props-spec.ts +0 -234
  272. package/tests/runtime/condition.spec.ts +0 -19
  273. package/tests/runtime/if-is.spec.ts +0 -390
  274. package/tests/runtime/map-and-convert.test.ts +0 -31
  275. package/tests/runtime/type.spec.ts +0 -190
  276. package/tests/strArrayToDict-spec.ts +0 -40
  277. package/tests/tuples/TupleToUnion.spec.ts +0 -20
  278. package/tests/withValue.spec.ts +0 -173
  279. package/tsconfig.json +0 -36
  280. package/vitest.config.ts +0 -17
@@ -1,390 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import type { Expect, Equal } from "@type-challenges/utils";
4
- import {
5
- ifArray,
6
- ifArrayPartial,
7
- ifBoolean,
8
- ifNumber,
9
- ifSameType,
10
- ifString,
11
- ifTrue,
12
- ifUndefined,
13
- isTrue,
14
- } from "src/runtime/type-checks";
15
- import { EndsWith, Extends, LowerAlpha, Or, StartsWith } from "src/types";
16
- import { ifStartsWith, startsWith } from "src/runtime/type-checks/startsWith";
17
- import { box, wide } from "src/runtime/literals";
18
- import { or } from "src/runtime";
19
-
20
- describe("runtime if/is", () => {
21
- it("ifString(v,i,e)", () => {
22
- const t = ifString("foo", () => 42, false);
23
- const f = ifString(-1, () => "yikes", 42);
24
-
25
- type cases = [
26
- Expect<Equal<typeof t, 42>>, //
27
- Expect<Equal<typeof f, 42>> //
28
- ];
29
- const cases: cases = [true, true];
30
- });
31
-
32
- it("ifNumber(v,i,e)", () => {
33
- const t = ifNumber(42, 42, false);
34
- const f = ifNumber("foo", "yikes", 42);
35
-
36
- type cases = [
37
- Expect<Equal<typeof t, 42>>, //
38
- Expect<Equal<typeof f, 42>> //
39
- ];
40
- const cases: cases = [true, true];
41
- });
42
-
43
- it("ifBoolean(v,i,e)", () => {
44
- const t = ifBoolean(false, 42, false);
45
- const f = ifBoolean(undefined, "yikes", 42);
46
-
47
- type cases = [
48
- Expect<Equal<typeof t, 42>>, //
49
- Expect<Equal<typeof f, 42>> //
50
- ];
51
- const cases: cases = [true, true];
52
- });
53
-
54
- it("ifTrue(v,i,e)", () => {
55
- const t = ifTrue(true as true, 42, false);
56
- const f = ifTrue(false, "yikes", 42);
57
- const f2 = ifTrue(true as boolean, "yikes", 42);
58
-
59
- type cases = [
60
- Expect<Equal<typeof t, 42>>, //
61
- Expect<Equal<typeof f, 42>>, //
62
- Expect<Equal<typeof f2, "yikes" | 42>> //
63
- ];
64
- const cases: cases = [true, true, true];
65
- });
66
-
67
- it("ifTrue(v,i,e) with boxed functions", () => {
68
- const f1 = box(<T extends string>(input: T) => `Hello ${input}` as const);
69
- const f2 = box(<T extends string>(input: T) => `Get out ${input}!` as const);
70
- const t = <T extends string, B extends boolean>(i: T, nice: B) => {
71
- return isTrue(nice) ? f1.value(i) : f2.value(i);
72
- };
73
- const t2 = <T extends string, B extends boolean>(i: T, nice: B) =>
74
- ifTrue(nice, f1.value(i), f2.value(i));
75
-
76
- // both approaches produce correct result
77
- const r1 = t("Joe", true);
78
- const r2 = t2("Joe", true);
79
- expect(r1).toBe("Hello Joe");
80
- expect(r2).toBe("Hello Joe");
81
-
82
- // only the "ifTrue" approach resolves fully at design time
83
- type R1 = typeof r1;
84
- type R2 = typeof r2;
85
-
86
- type cases = [
87
- // still get union type with `isTrue` conditional
88
- Expect<Equal<R1, "Hello Joe" | "Get out Joe!">>,
89
- // but encapsulating both outcomes in `ifTrue` resolves the union
90
- Expect<Equal<R2, "Hello Joe">>
91
- ];
92
- const cases: cases = [true, true];
93
- });
94
-
95
- it("ifTrue(v,i,e) with string literal functions", () => {
96
- const f1 = <T extends string>(input: T) => `Hello ${input}` as const;
97
- const f2 = <T extends string>(input: T) => `Get out ${input}!` as const;
98
- const t = <T extends string, B extends boolean>(i: T, nice: B) => {
99
- return isTrue(nice) ? f1(i) : f2(i);
100
- };
101
- const t2 = <T extends string, B extends boolean>(i: T, nice: B) => ifTrue(nice, f1(i), f2(i));
102
-
103
- // both approaches produce correct result
104
- const r1 = t("Joe", true);
105
- const r2 = t2("Joe", true);
106
- expect(r1).toBe("Hello Joe");
107
- expect(r2).toBe("Hello Joe");
108
-
109
- // only the "ifTrue" approach resolves fully at design time
110
- type R1 = typeof r1;
111
- type R2 = typeof r2;
112
-
113
- type cases = [
114
- // still get union type with `isTrue` conditional
115
- Expect<Equal<R1, "Hello Joe" | "Get out Joe!">>,
116
- // but encapsulating both outcomes in `ifTrue` resolves the union
117
- Expect<Equal<R2, "Hello Joe">>
118
- ];
119
- const cases: cases = [true, true];
120
- });
121
-
122
- it("Or<T[]> type util", () => {
123
- type T1 = Or<[true, true, false]>;
124
- type T2 = Or<[false, false, false]>;
125
- type T3 = Or<[boolean, boolean, true]>;
126
- type T4 = Or<[boolean, boolean, boolean]>;
127
-
128
- type cases = [
129
- Expect<Equal<T1, true>>,
130
- Expect<Equal<T2, false>>,
131
- Expect<Equal<T3, true>>,
132
- Expect<Equal<T4, boolean>>
133
- ];
134
- const cases: cases = [true, true, true, true];
135
- });
136
-
137
- it("or() runtime utility", () => {
138
- const t1 = or(true, true, false);
139
- const t2 = or(false, false, false);
140
- const t3 = or(false as boolean, false, true);
141
- const t4 = or(false as boolean, false as boolean, true as boolean);
142
-
143
- type cases = [
144
- Expect<Equal<typeof t1, true>>,
145
- Expect<Equal<typeof t2, false>>,
146
- Expect<Equal<typeof t3, true>>,
147
- Expect<Equal<typeof t4, boolean>>
148
- ];
149
- const cases: cases = [true, true, true, true];
150
-
151
- expect(t1).toBe(true);
152
- expect(t2).toBe(false);
153
- expect(t3).toBe(true);
154
- expect(t4).toBe(true);
155
- });
156
-
157
- it("Extends<T,EXTENDS> with single clause", () => {
158
- type cases = [
159
- //
160
- Expect<Equal<Extends<1, number>, true>>,
161
- Expect<Equal<Extends<2, string>, false>>,
162
- Expect<Equal<Extends<2, 2 | 3>, true>>
163
- ];
164
- const cases: cases = [true, true, true];
165
- });
166
-
167
- it("IfExtends<T,EXTENDS,IF,ELSE", () => {
168
- type cases = [/** type tests */];
169
- const cases: cases = [];
170
- });
171
-
172
- it("ifArray(val,if,else) utility", () => {
173
- const fn0 = ifArray(
174
- "foobar" as string,
175
- (i) => `I'm an array, my length is ${i.length}` as const,
176
- (i) => `I'm not an array, I am ${i}` as const
177
- );
178
- const fn1 = ifArray(
179
- "foobar",
180
- (i) => `I'm an array, my length is ${i.length}` as const,
181
- (i) => `I'm not an array, I am ${i}` as const
182
- );
183
- const fn2 = ifArray(
184
- ["foo", "bar"] as const,
185
- (i) => `I'm an array, my length is ${i.length}` as const,
186
- (i) => `I'm not an array, I am ${i}` as const
187
- );
188
-
189
- const fn3 = ifArray(
190
- ["foo", "bar"],
191
- (i) => `I'm an array, my length is ${i.length}` as const,
192
- (i) => `I'm not an array, I am ${i}` as const
193
- );
194
-
195
- type cases = [
196
- Expect<Equal<typeof fn0, `I'm not an array, I am ${string}`>>,
197
- Expect<Equal<typeof fn1, `I'm not an array, I am foobar`>>,
198
- Expect<Equal<typeof fn2, `I'm an array, my length is 2`>>,
199
- Expect<Equal<typeof fn3, `I'm an array, my length is ${number}`>>
200
- ];
201
- const cases: cases = [true, true, true, true];
202
- });
203
-
204
- it("ifArrayPartial()()", () => {
205
- const arrTest = ifArrayPartial<string | string[]>()(
206
- (i) => `I'm an array, my length is ${i.length}`,
207
- (i) => `I'm not an array, I am ${i}`
208
- );
209
-
210
- const t1 = arrTest("Bob");
211
- const t2 = arrTest(["foo", "bar"]);
212
-
213
- type cases = [
214
- Expect<Equal<typeof t1, `I'm not an array, I am ${string}`>>,
215
- Expect<Equal<typeof t2, `I'm an array, my length is ${number}`>>
216
- ];
217
- const cases: cases = [true, true];
218
- });
219
-
220
- it("ifUndefined(v,i,e)", () => {
221
- const t = ifUndefined(undefined, 42, false);
222
- const f = ifUndefined(false, "yikes", 42);
223
- const f2 = ifUndefined("", "yikes", 42);
224
-
225
- type cases = [
226
- Expect<Equal<typeof t, 42>>, //
227
- Expect<Equal<typeof f, 42>>, //
228
- Expect<Equal<typeof f2, 42>> //
229
- ];
230
- const cases: cases = [true, true, true];
231
- });
232
-
233
- it("StartsWith<T,U>", () => {
234
- type T1 = StartsWith<"foobar", "foo">;
235
- type T2 = StartsWith<"foobar", "foot">;
236
- type T3 = StartsWith<"foobar", string>;
237
- type T4 = StartsWith<string, "foo">;
238
- type T5 = StartsWith<string, string>;
239
-
240
- type T6 = StartsWith<"alpha", LowerAlpha>;
241
- type T7 = StartsWith<"Alpha", LowerAlpha>;
242
-
243
- type cases = [
244
- Expect<Equal<T1, true>>, //
245
- Expect<Equal<T2, false>>,
246
- // if either the "start with" or "val" props are wide then we can't resolve at design time
247
- Expect<Equal<T3, boolean>>,
248
- Expect<Equal<T4, boolean>>,
249
- Expect<Equal<T5, boolean>>,
250
- // LowerAlpha is a string literal
251
- Expect<Equal<T6, true>>,
252
- Expect<Equal<T7, false>>
253
- ];
254
- const cases: cases = [true, true, true, true, true, true, true];
255
- });
256
-
257
- it("EndsWith<T,U>", () => {
258
- type T1 = EndsWith<"foobar", "bar">;
259
- type T2 = EndsWith<"foobar", "bart">;
260
- type T3 = EndsWith<"foobar", string>;
261
- type T4 = EndsWith<string, "bar">;
262
- type T5 = EndsWith<string, string>;
263
-
264
- type cases = [
265
- Expect<Equal<T1, true>>, //
266
- Expect<Equal<T2, false>>,
267
- Expect<Equal<T3, boolean>>,
268
- Expect<Equal<T4, boolean>>,
269
- Expect<Equal<T5, boolean>>
270
- ];
271
- const cases: cases = [true, true, true, true, true];
272
- });
273
-
274
- it("startsWith(t)(v)", () => {
275
- const t1 = startsWith("foo")("foobar");
276
- const t2 = startsWith("foot")("foobar");
277
- const p1 = startsWith("foo");
278
-
279
- // runtime
280
- expect(t1).toBe(true);
281
- expect(t2).toBe(false);
282
- expect(p1("foot")).toBe(true);
283
- expect(p1("bart")).toBe(false);
284
-
285
- // design time
286
- type cases = [
287
- Expect<Equal<typeof t1, true>>, //
288
- Expect<Equal<typeof t2, false>> //
289
- ];
290
- const cases: cases = [true, true];
291
- });
292
-
293
- it("ifStartsWith(start, isTrue, isFalse)(v)", () => {
294
- const noSir = <T extends string>(i: T) => `no sir didn't like it ${i}` as const;
295
- const startWithFoo = ifStartsWith(
296
- // condition
297
- "foo",
298
- // inline
299
- (i) => `welcome ${i}`,
300
- // external
301
- noSir
302
- );
303
- const t = startWithFoo("foobar");
304
- type T = typeof t;
305
- const f = startWithFoo("nope");
306
- type F = typeof f;
307
-
308
- type FS = typeof startWithFoo;
309
- type RFS = ReturnType<FS>;
310
-
311
- // runtime
312
- expect(t).toBe("welcome foobar");
313
- expect(f).toBe("no sir didn't like it nope");
314
-
315
- // TODO: get the design time to be more literal
316
-
317
- type cases = [
318
- Expect<Equal<T, `welcome ${string}`>>,
319
- Expect<Equal<F, `no sir didn't like it ${string}`>>,
320
- Expect<
321
- Equal<
322
- //
323
- RFS,
324
- `welcome ${string}` | `no sir didn't like it ${string}`
325
- >
326
- >
327
- ];
328
- const cases: cases = [true, true, true];
329
- });
330
-
331
- it("ifSameType", () => {
332
- const t1 = ifSameType(
333
- "foo",
334
- wide.string,
335
- (i) => `Hello ${i}`,
336
- (i) => `Goodbye ${i}`
337
- );
338
- const t2 = ifSameType(
339
- 42,
340
- wide.string,
341
- (i) => `Hello ${i}`,
342
- (i) => `Goodbye ${i}`
343
- );
344
- const t3 = ifSameType(
345
- "foo" as string,
346
- wide.string,
347
- (i) => `Hello ${i}`,
348
- (i) => `Goodbye ${i}`
349
- );
350
- const t4 = ifSameType(
351
- 42 as number,
352
- wide.string,
353
- (i) => `Hello ${i}`,
354
- (i) => `Goodbye ${i}`
355
- );
356
-
357
- const nested = ifSameType(
358
- false,
359
- wide.string,
360
- (i) => `Hello ${i}`,
361
- (i) =>
362
- ifSameType(
363
- i,
364
- wide.number,
365
- (n) => n,
366
- (i) =>
367
- ifSameType(
368
- i,
369
- wide.boolean,
370
- (b) => `I'm a boolean value of ${b}`,
371
- () => ""
372
- )
373
- )
374
- );
375
-
376
- type cases = [
377
- // matches (narrow)
378
- Expect<Equal<typeof t1, "Hello foo">>,
379
- // does not match (narrow)
380
- Expect<Equal<typeof t2, `Goodbye 42`>>,
381
- // matches (wide)
382
- Expect<Equal<typeof t3, `Hello ${string}`>>,
383
- // does not match (wide)
384
- Expect<Equal<typeof t4, `Goodbye ${number}`>>,
385
- // nested
386
- Expect<Equal<typeof nested, `I'm a boolean value of false`>>
387
- ];
388
- const cases: cases = [true, true, true, true, true];
389
- });
390
- });
@@ -1,31 +0,0 @@
1
- import { Equal, Expect } from "@type-challenges/utils";
2
- import { createConverter } from "src/runtime/lists/createConverter";
3
- import { describe, it, expect } from "vitest";
4
-
5
- // Note: while type tests fail visible inspection they pass from Vitest
6
- // standpoint so always be sure to run `tsc --noEmit` over your test files to
7
- // gain validation that no new type vulnerabilities have cropped up.
8
-
9
- describe("createConverter()", () => {
10
- it("basic converter setup", () => {
11
- const convert = createConverter({
12
- string: (s) => `Hello ${s}`,
13
- number: (n) => `The number was ${n}`,
14
- object: (o) => `An object with keys ${Object.keys(o).join(", ")}`,
15
- });
16
-
17
- const t1 = convert("foo");
18
- const t2 = convert(42);
19
- const t3 = convert({ foo: 42, bar: 12 });
20
- expect(t1).toBe("Hello foo");
21
- expect(t2).toBe("The number was 42");
22
-
23
- type cases = [
24
- // TODO: get the final narrowness resolved ... this should be doable
25
- Expect<Equal<typeof t1, `Hello ${string}`>>,
26
- Expect<Equal<typeof t2, `The number was ${number}`>>,
27
- Expect<Equal<typeof t3, `An object with keys ${string}`>>
28
- ];
29
- const cases: cases = [true, true, true];
30
- });
31
- });
@@ -1,190 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
-
3
- import type { Expect, Equal } from "@type-challenges/utils";
4
- import { FunctionType } from "src/types";
5
- import { type, createFnWithProps, isFunction, isObject } from "src/runtime";
6
-
7
- describe("testing type() utility and some pre-made conditions", () => {
8
- it("isFunction()", () => {
9
- const fn = () => "hello world";
10
- const fn2 = createFnWithProps(() => "hello world", { foo: "bar" });
11
- const t1 = isFunction(fn);
12
- const t2 = isFunction(fn2);
13
- type T1 = typeof t1;
14
- type T2 = typeof t2;
15
-
16
- expect(t1).toBe(true);
17
- expect(t2).toBe(true);
18
-
19
- type cases = [
20
- // a simple function is correctly typed (no surprise)
21
- Expect<Equal<T1, true>>,
22
- // but so is a function which has props; using just _typeof_
23
- // not work
24
- Expect<Equal<T2, true>>
25
- ];
26
-
27
- const c: cases = [true, true];
28
- expect(c).toBe(c);
29
- });
30
-
31
- it("isObject detects object which are not arrays and not functions with props", () => {
32
- const fnWithProps = createFnWithProps(() => "hi", { foo: "bar" });
33
- const obj = {
34
- foo: 1,
35
- bar: { left: "left", right: "right" },
36
- baz: [1, 2, 3],
37
- fnWithProps,
38
- } as const;
39
-
40
- const foo = isObject(obj.foo);
41
- const bar = isObject(obj.bar);
42
- const baz = isObject(obj.baz);
43
- const fnWithProps2 = isObject(obj.fnWithProps);
44
-
45
- // run-time
46
- expect(foo).toBeFalsy();
47
- expect(bar).toBeTruthy();
48
- expect(baz).toBeFalsy();
49
- expect(fnWithProps2).toBeFalsy();
50
-
51
- // type checking
52
- type cases = [
53
- // all tests should result in a discrete, literal true/false
54
- Expect<Equal<typeof foo, false>>,
55
- Expect<Equal<typeof bar, true>>,
56
- Expect<Equal<typeof baz, false>>,
57
- Expect<Equal<typeof fnWithProps2, false>>
58
- ];
59
-
60
- const c: cases = [true, true, true, true];
61
- expect(c).toBe(c);
62
- });
63
-
64
- it("an object can be detected using type() utility", () => {
65
- const fnWithProps = createFnWithProps(() => "hi", { foo: "bar" });
66
- const obj = {
67
- foo: 1,
68
- bar: { left: "left", right: "right" },
69
- baz: [1, 2, 3],
70
- fnWithProps,
71
- } as const;
72
- const o = type((t) => t.object);
73
-
74
- const foo = o.is(obj.foo);
75
- const bar = o.is(obj.bar);
76
- const baz = o.is(obj.baz);
77
- const fnWithProps2 = o.is(obj.fnWithProps);
78
-
79
- // run-time
80
- expect(foo).toBeFalsy();
81
- expect(bar).toBeTruthy();
82
- expect(baz).toBeFalsy();
83
- expect(fnWithProps2).toBeFalsy();
84
-
85
- // type checking
86
- type cases = [
87
- // all tests should result in a discrete, literal true/false
88
- Expect<Equal<typeof foo, false>>,
89
- Expect<Equal<typeof bar, true>>,
90
- Expect<Equal<typeof baz, false>>,
91
- Expect<Equal<typeof fnWithProps2, false>>
92
- ];
93
-
94
- const c: cases = [true, true, true, true];
95
- expect(c).toBe(c);
96
- });
97
-
98
- it("defining a boolean type", () => {
99
- const b = type((t) => t.boolean);
100
-
101
- type TypeOf = typeof b.type;
102
-
103
- expect(b.name).toBe("boolean");
104
-
105
- const trueTest = b.is(true);
106
- const falseTest = b.is(false);
107
- const nadaTest = b.is("nada");
108
-
109
- expect(trueTest).toBe(true);
110
- expect(falseTest).toBe(true);
111
- expect(nadaTest).toBe(false);
112
-
113
- type cases = [
114
- //
115
- Expect<Equal<TypeOf, boolean>>,
116
- Expect<Equal<typeof trueTest, true>>,
117
- Expect<Equal<typeof falseTest, true>>,
118
- Expect<Equal<typeof nadaTest, false>>
119
- ];
120
-
121
- const c: cases = [true, true, true, true];
122
- expect(c).toBe(c);
123
- });
124
-
125
- it("defining true type", () => {
126
- const t = type((t) => t.true);
127
-
128
- const typeOf = t.type;
129
- type TypeOf = typeof typeOf;
130
-
131
- expect(t.name).toBe("true");
132
-
133
- const trueIsTrue = t.is(true as true);
134
- const falseNotTrue = t.is(false as false);
135
- const nadaNotTrue = t.is("nada");
136
- const b = true as boolean;
137
- const booleanUnknown = t.is(b);
138
-
139
- expect(trueIsTrue).toBe(true);
140
- expect(falseNotTrue).toBe(false);
141
- expect(nadaNotTrue).toBe(false);
142
- // run-time can evaluate, but type system not sure
143
- expect(booleanUnknown).toBe(true);
144
-
145
- // TODO: return the final type test below to "unknown" versus "boolean" once there's a fix
146
-
147
- type cases = [
148
- //
149
- Expect<Equal<TypeOf, true>>,
150
- Expect<Equal<typeof trueIsTrue, true>>,
151
- Expect<Equal<typeof falseNotTrue, false>>,
152
- Expect<Equal<typeof nadaNotTrue, false>>,
153
- // the type system has no way of knowing
154
- // because the wide type of "boolean" is
155
- // a union type which includes true
156
- Expect<Equal<typeof booleanUnknown, boolean>>
157
- ];
158
-
159
- const c: cases = [true, true, true, true, true];
160
- expect(c).toBe(c);
161
- });
162
-
163
- it("defining a function type", () => {
164
- const t = type((t) => t.function);
165
-
166
- const typeOf = t.type;
167
- type TypeOf = typeof typeOf;
168
-
169
- expect(t.name).toBe("function");
170
-
171
- const basicFn = t.is(() => "hi");
172
- const fnWithProps = t.is(createFnWithProps(() => "hi", { foo: "bar" }));
173
- const nadaTest = t.is("nada");
174
-
175
- expect(basicFn).toBe(true);
176
- expect(fnWithProps).toBe(true);
177
- expect(nadaTest).toBe(false);
178
-
179
- type cases = [
180
- //
181
- Expect<Equal<TypeOf, FunctionType>>,
182
- Expect<Equal<typeof basicFn, true>>,
183
- Expect<Equal<typeof fnWithProps, true>>,
184
- Expect<Equal<typeof nadaTest, false>>
185
- ];
186
-
187
- const c: cases = [true, true, true, true];
188
- expect(c).toBe(c);
189
- });
190
- });
@@ -1,40 +0,0 @@
1
- import { describe, it } from "vitest";
2
-
3
- import { literal, strArrayToDict } from "../src/runtime";
4
- import type { Expect, Equal, ExpectFalse } from "@type-challenges/utils";
5
-
6
- describe("strArrayToDict() utility", () => {
7
- it("", () => {
8
- const result = strArrayToDict("a", "b", "c");
9
- type R = typeof result;
10
-
11
- const start = ["a", "b", "c"] as const;
12
- const result2 = strArrayToDict(...start);
13
- type R2 = typeof result2;
14
-
15
- const start3 = literal(["a", "b", "c"]);
16
- const result3 = strArrayToDict(...start3);
17
- type R3 = typeof result3;
18
-
19
- const start4 = ["a", "b", "c"];
20
- const result4 = strArrayToDict(...start4);
21
- type R4 = typeof result4;
22
-
23
- type cases = [
24
- // as long as we ensure that the array consists of literals
25
- // we are good for the conversion
26
- Expect<Equal<R, { a: true; b: true; c: true }>>,
27
- Expect<Equal<R2, { a: true; b: true; c: true }>>,
28
- Expect<Equal<R3, { a: true; b: true; c: true }>>,
29
- // but a non-literal array doesn't work
30
- // TODO: see if there's a way to force input to be literal
31
- ExpectFalse<Equal<R4, { a: true; b: true; c: true }>>,
32
- // and unfortunately it's lost all track of the keys
33
- // which are involved; just knowning that they are
34
- // string based keys
35
- Expect<Equal<keyof R4, string>>
36
- ];
37
-
38
- const cases: cases = [true, true, true, false, true];
39
- });
40
- });
@@ -1,20 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
-
3
- import { TupleToUnion } from "src/types";
4
- import { Expect, Equal } from "@type-challenges/utils";
5
-
6
- describe("TupleToUnion<T> type utility", () => {
7
- it("an array of literals is converted ot a tuple", () => {
8
- const arr = [1, 2, 5] as const;
9
- type Arr = typeof arr;
10
- type Union = TupleToUnion<Arr>;
11
-
12
- type cases = [
13
- //
14
- Expect<Equal<Union, 1 | 2 | 5>>
15
- ];
16
-
17
- const c: cases = [true];
18
- expect(c).toBe(c);
19
- });
20
- });