inferred-types 0.20.0 → 0.22.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.
Files changed (131) hide show
  1. package/.eslintrc +36 -20
  2. package/.github/workflows/main.yml +34 -0
  3. package/.github/workflows/other.yml +15 -0
  4. package/.vscode/settings.json +10 -2
  5. package/dist/index.d.ts +398 -8541
  6. package/dist/index.js +17 -60
  7. package/dist/index.mjs +8 -48
  8. package/package.json +32 -24
  9. package/src/shared/valueTypes.ts +1 -1
  10. package/src/types/ExpandRecursively.ts +10 -1
  11. package/src/types/SimplifyObject.ts +12 -0
  12. package/src/types/Transformer.ts +1 -1
  13. package/src/types/alphabetic/CamelCase.ts +1 -1
  14. package/src/types/alphabetic/CapFirstAlpha.ts +7 -3
  15. package/src/types/alphabetic/Dasherize.ts +8 -5
  16. package/src/types/alphabetic/KebabCase.ts +1 -1
  17. package/src/types/alphabetic/PascalCase.ts +3 -1
  18. package/src/types/alphabetic/SnakeCase.ts +8 -3
  19. package/src/types/dictionary/DictPartialApplication.ts +30 -0
  20. package/src/types/dictionary/DictPrependWithFn.ts +23 -0
  21. package/src/types/dictionary/DictReturnValues.ts +27 -0
  22. package/src/types/dictionary/RequireProps.ts +15 -0
  23. package/src/types/{type-conversion → dictionary}/SameKeys.ts +0 -0
  24. package/src/types/dictionary/index.ts +8 -3
  25. package/src/types/{props.ts → dictionary/props.ts} +1 -1
  26. package/src/types/functions/FinalReturn.ts +12 -0
  27. package/{on-hold/types → src/types/functions}/index.ts +4 -3
  28. package/src/types/index.ts +4 -3
  29. package/src/types/ruleset-types.ts +3 -3
  30. package/src/types/runtime.ts +18 -18
  31. package/src/types/string-literals/LeftWhitespace.ts +5 -2
  32. package/src/types/string-literals/RightWhitespace.ts +5 -2
  33. package/src/types/tuples/FirstKey.ts +3 -3
  34. package/src/types/tuples/FromDictArray.ts +5 -4
  35. package/src/types/type-conversion/index.ts +2 -5
  36. package/src/utility/api/api.ts +8 -7
  37. package/src/utility/dictionary/dictionaryTransform.ts +5 -4
  38. package/src/utility/dictionary/entries.ts +9 -5
  39. package/src/utility/dictionary/index.ts +2 -3
  40. package/src/utility/dictionary/kv/dictToKv.ts +5 -3
  41. package/src/utility/dictionary/kv/filterDictArray.ts +5 -7
  42. package/src/utility/dictionary/kv/kv.ts +8 -3
  43. package/src/utility/dictionary/kv/kvToDict.ts +3 -2
  44. package/src/utility/dictionary/mapValues.ts +8 -5
  45. package/src/utility/dictionary/strArrayToDict.ts +1 -2
  46. package/src/utility/keys.ts +8 -4
  47. package/src/utility/lists/groupBy.ts +2 -9
  48. package/src/utility/literals/arrayToObject.ts +29 -29
  49. package/src/utility/literals/defineType.ts +6 -6
  50. package/src/utility/literals/identity.ts +5 -2
  51. package/src/utility/literals/literal.ts +3 -3
  52. package/src/utility/ruleset.ts +11 -9
  53. package/src/utility/runtime/condition.ts +1 -1
  54. package/src/utility/runtime/conditions/isFalse.ts +2 -2
  55. package/src/utility/runtime/conditions/isFunction.ts +2 -2
  56. package/src/utility/runtime/conditions/isObject.ts +4 -1
  57. package/src/utility/runtime/conditions/isTrue.ts +1 -1
  58. package/src/utility/runtime/ifTypeOf.ts +1 -1
  59. package/src/utility/runtime/type.ts +3 -1
  60. package/src/utility/runtime/withValue.ts +5 -3
  61. package/src/utility/state/Configurator.ts +2 -2
  62. package/src/utility/state/FluentConfigurator.ts +2 -2
  63. package/src/utility/state/index.ts +2 -3
  64. package/tests/CamelCase-spec.ts +2 -0
  65. package/tests/ExplicitFunction-spec.ts +3 -2
  66. package/tests/IncludeAndRetain-spec.ts +7 -12
  67. package/tests/Includes-spec.ts +2 -0
  68. package/tests/KebabCase-spec.ts +2 -0
  69. package/tests/MutationIdentity-spec.ts +2 -1
  70. package/tests/PascalCase-spec.ts +2 -0
  71. package/tests/Pluralize-spec.ts +2 -0
  72. package/tests/SnakeCase-spec.ts +2 -0
  73. package/tests/Where.spec.ts +9 -10
  74. package/tests/arrayToKeyLookup-spec.ts +5 -5
  75. package/tests/arrayToObject-spec.ts +12 -8
  76. package/tests/constructor.spec.ts +2 -0
  77. package/tests/createFnWithProps.spec.ts +2 -2
  78. package/tests/defineType-spec.ts +17 -11
  79. package/tests/dictionary/DictPartialApplication.test.ts +43 -0
  80. package/tests/dictionary/DictReturnValues.test.ts +32 -0
  81. package/tests/dictionary/Get.spec.ts +5 -3
  82. package/tests/dictionary/PrependValuesWithFunction.ts +34 -0
  83. package/tests/dictionary/RequireProps.test.ts +21 -0
  84. package/tests/dictionaryTransform-spec.ts +3 -3
  85. package/tests/ifTypeOf-spec.ts +31 -20
  86. package/tests/kv/KeyValue-spec.ts +4 -4
  87. package/tests/kv/SameKeys-spec.ts +6 -9
  88. package/tests/kv/dict-to-kv-and-back.spec.ts +5 -4
  89. package/tests/kv/entries-spec.ts +8 -9
  90. package/tests/kv/keys.spec.ts +9 -19
  91. package/tests/kv/kv-spec.ts +4 -4
  92. package/tests/lists/UniqueForProp.spec.ts +3 -1
  93. package/tests/literal-spec.ts +5 -3
  94. package/tests/mapValues-spec.ts +5 -3
  95. package/tests/props-spec.ts +3 -2
  96. package/tests/runtime/condition.spec.ts +2 -1
  97. package/tests/runtime/type.spec.ts +4 -3
  98. package/tests/strArrayToDict-spec.ts +6 -6
  99. package/tests/string-literals/AllCaps.spec.ts +6 -15
  100. package/tests/string-literals/CamelCase.spec.ts +13 -32
  101. package/tests/string-literals/Dasherize.spec.ts +13 -31
  102. package/tests/string-literals/HasUppercase.spec.ts +6 -15
  103. package/tests/string-literals/PascalCase.spec.ts +13 -32
  104. package/tests/string-literals/SnakeCase.spec.ts +13 -32
  105. package/tests/string-literals/whitespace-capture.spec.ts +10 -28
  106. package/tests/tuples/TupleToUnion.spec.ts +3 -1
  107. package/tests/withValue.spec.ts +4 -3
  108. package/tsconfig.json +8 -19
  109. package/vitest.config.ts +13 -0
  110. package/jest.config.ts +0 -20
  111. package/on-hold/Builder/Builder.ts +0 -66
  112. package/on-hold/Builder/BuilderApi.ts +0 -21
  113. package/on-hold/Builder/IdentityToMutationApi.ts +0 -44
  114. package/on-hold/Builder/MutationToFluentApi.ts +0 -60
  115. package/on-hold/Builder/index.ts +0 -35
  116. package/on-hold/tests/Builder-spec.ts +0 -310
  117. package/on-hold/tests/RuleSet-spec.ts +0 -59
  118. package/on-hold/tests/ToFluent-spec.ts +0 -60
  119. package/on-hold/tests/api-spec.ts +0 -73
  120. package/on-hold/tests/data/builder-data.ts +0 -53
  121. package/on-hold/tests/filterDictArray-spec.ts +0 -50
  122. package/on-hold/tests/run-time-spec.ts +0 -44
  123. package/on-hold/type.ts +0 -20
  124. package/on-hold/types/object.ts +0 -19
  125. package/on-hold/types/prop.ts +0 -28
  126. package/on-hold/types/scalar.ts +0 -37
  127. package/src/types/dictionary/NotEmptyObject.ts +0 -9
  128. package/src/types/type-conversion/UnwrapValue.ts +0 -13
  129. package/src/types/type-conversion/WrapValue.ts +0 -15
  130. package/src/utility/dictionary/valuesOfProp.ts +0 -13
  131. package/src/utility/state/KeyStorage.ts +0 -23
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-use-before-define */
2
- import type { Narrowable } from "~/types";
2
+
3
+ import { Narrowable } from "src/types/Narrowable";
3
4
 
4
5
  // TODO: get ruleset functionality working!
5
6
 
@@ -15,21 +16,23 @@ import type { Narrowable } from "~/types";
15
16
 
16
17
  /**
17
18
  * **ruleSet**
18
- *
19
+ *
19
20
  * Defines a ruleset composed of _dynamic_ and _static_ boolean operators.
20
- *
21
+ *
21
22
  * - the first function call defines _dynamic_ props (_optional_)
22
23
  * - the second function call defines static values
23
- *
24
+ *
24
25
  * ```ts
25
- * const rs = ruleSet(
26
+ * const rs = ruleSet(
26
27
  * r => r.state()( { maybe: r => r.extends({ foo: 1 }) })
27
- * )(
28
- * { color: true, age: false }
28
+ * )(
29
+ * { color: true, age: false }
29
30
  * );
30
31
  * ```
31
32
  */
32
- export function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(defn?: TState) {
33
+ export function ruleSet<N extends Narrowable, TState extends Record<keyof TState, N>>(
34
+ defn?: TState
35
+ ) {
33
36
  // return <
34
37
  // TStatic extends { [K in keyof TStatic]: Readonly<true | false> },
35
38
  // >(rules: TStatic) => {
@@ -37,4 +40,3 @@ export function ruleSet<N extends Narrowable, TState extends Record<keyof TState
37
40
  // };
38
41
  return defn;
39
42
  }
40
-
@@ -1,4 +1,4 @@
1
- import { Narrowable } from "~/types";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
 
3
3
  export type Condition<TInput extends Narrowable, TResult extends boolean> = (
4
4
  input: TInput
@@ -1,5 +1,5 @@
1
- import { Narrowable } from "~/types";
2
- import { IsBoolean } from "~/utility";
1
+ import { Narrowable } from "src/types/Narrowable";
2
+ import { IsBoolean } from "./isBoolean";
3
3
 
4
4
  export type IsFalse<T extends Narrowable> = IsBoolean<T> extends true
5
5
  ? // is a boolean
@@ -1,4 +1,4 @@
1
- import { FunctionType } from "~/types";
1
+ import { FunctionType } from "src/types/FunctionType";
2
2
 
3
3
  export type IsFunction<T> = T extends FunctionType ? true : false;
4
4
 
@@ -11,7 +11,7 @@ export type IsFunction<T> = T extends FunctionType ? true : false;
11
11
  * ```
12
12
  *
13
13
  * Note: the runtime `typeof [variable]` will correctly say "function" when a function is
14
- * encounted but if that function also has object types defined then the type will be a big
14
+ * encountered but if that function also has object types defined then the type will be a big
15
15
  * and ugly union type. This function will give you a proper boolean value in both cases.
16
16
  */
17
17
  export function isFunction<T extends unknown>(input: T): IsFunction<T> {
@@ -1,4 +1,7 @@
1
- import { FunctionType, Mutable, Narrowable, Not } from "~/types";
1
+ import { FunctionType } from "src/types/FunctionType";
2
+ import { Mutable } from "src/types/Mutable";
3
+ import { Narrowable } from "src/types/Narrowable";
4
+ import { Not } from "src/types/Not";
2
5
 
3
6
  export type IsObject<T> = Mutable<T> extends Record<string, any>
4
7
  ? // an object of some type
@@ -1,4 +1,4 @@
1
- import { Narrowable } from "~/types";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
  import type { IsBoolean } from "./isBoolean";
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Narrowable } from "~/types/Narrowable";
1
+ import { Narrowable } from "src/types/Narrowable";
2
2
  import { keys } from "../keys";
3
3
 
4
4
  function runtimeExtendsCheck<TValue extends any, TBase extends any>(
@@ -1,4 +1,6 @@
1
- import { FunctionType, Narrowable, TypeGuard } from "~/types";
1
+ import { FunctionType } from "src/types/FunctionType";
2
+ import { Narrowable } from "src/types/Narrowable";
3
+ import { TypeGuard } from "src/types/TypeGuard";
2
4
  import {
3
5
  isString,
4
6
  isBoolean,
@@ -1,8 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
 
3
- import { ExpandRecursively, Narrowable, WithValue } from "~/types";
4
- import { entries } from "~/utility/dictionary";
5
- import { type, TypeDefinition } from "~/utility/runtime";
3
+ import { WithValue } from "src/types/dictionary";
4
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
5
+ import { Narrowable } from "src/types/Narrowable";
6
+ import { entries } from "../dictionary/entries";
7
+ import { type, TypeDefinition } from "./type";
6
8
 
7
9
  /**
8
10
  * **withValue**
@@ -1,4 +1,5 @@
1
- /* eslint-disable unicorn/consistent-function-scoping */
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
+
2
3
  type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3
4
  function omit<T extends {}, K extends Array<keyof T>>(obj: T, ...removals: K) {
4
5
  const untyped = removals as Array<unknown>;
@@ -8,7 +9,6 @@ function omit<T extends {}, K extends Array<keyof T>>(obj: T, ...removals: K) {
8
9
  >;
9
10
  }
10
11
 
11
- import { ExpandRecursively } from "~/types";
12
12
  export interface IConfigurator<C = {}> {
13
13
  set<V, K extends string, KV = { [U in K]: V }>(
14
14
  key: K,
@@ -1,4 +1,4 @@
1
- import type { ExpandRecursively } from "~/types";
1
+ import { ExpandRecursively } from "src/types/ExpandRecursively";
2
2
 
3
3
  export interface IFluentConfigurator<C> {
4
4
  /**
@@ -28,7 +28,7 @@ export function FluentConfigurator<I>(initial: I = {} as I) {
28
28
  const api = <C>(current: C): IFluentConfigurator<C> => {
29
29
  return {
30
30
  set<V, K extends string, KV = { [U in K]: V }>(key: K, value: V) {
31
- const keyValue = ({ [key]: value as V } as unknown) as KV;
31
+ const keyValue = { [key]: value as V } as unknown as KV;
32
32
  const updated = { ...keyValue, ...current };
33
33
 
34
34
  return api<C & KV>(updated);
@@ -1,12 +1,11 @@
1
1
  // #autoindex
2
2
  // #region autoindexed files
3
- // index last changed at: 1st Jan, 2022, 03:27 PM ( GMT-8 )
4
- // hash-code: fd5dfde8
3
+ // index last changed at: 7th Jul, 2022, 01:15 PM ( GMT-7 )
4
+ // hash-code: 14769606
5
5
 
6
6
  // file exports
7
7
  export * from "./Configurator";
8
8
  export * from "./FluentConfigurator";
9
- export * from "./KeyStorage";
10
9
 
11
10
  // #endregion
12
11
 
@@ -1,3 +1,5 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { CamelCase } from "../src/types";
2
4
  import { Expect, Equal } from "@type-challenges/utils";
3
5
 
@@ -1,5 +1,6 @@
1
- /* eslint-disable unicorn/consistent-function-scoping */
2
- import { ExplicitFunction } from "~/utility";
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ import { ExplicitFunction } from "../src/utility";
3
4
  import type { Expect, Equal } from "@type-challenges/utils";
4
5
 
5
6
  describe("ExplicitFunction()", () => {
@@ -1,4 +1,6 @@
1
- import { Include, Retain } from "~/types";
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ import { Include, Retain } from "../src/types";
2
4
  import { Equal, Expect } from "@type-challenges/utils";
3
5
 
4
6
  // INCLUDE
@@ -8,10 +10,7 @@ describe("Include<T, U> utility", () => {
8
10
  type Foo = Include<typeof str, string>;
9
11
  type NotFoo = Include<typeof str, number>;
10
12
 
11
- type cases = [
12
- Expect<Equal<Foo, "foo">>,
13
- Expect<Equal<NotFoo, never>>
14
- ];
13
+ type cases = [Expect<Equal<Foo, "foo">>, Expect<Equal<NotFoo, never>>];
15
14
  const c: cases = [true, true];
16
15
  expect(c).toBe(c);
17
16
  });
@@ -33,12 +32,11 @@ describe("Include<T, U> utility", () => {
33
32
  Expect<Equal<RelatedFoo, "foo">>,
34
33
  // this behavior is adjusted if you include
35
34
  // the optional `L` generic as a true value
36
- Expect<Equal<NotLiteralFoo, never>>,
35
+ Expect<Equal<NotLiteralFoo, never>>
37
36
  ];
38
37
  const c: cases = [true, true, true, true];
39
38
  expect(c).toBe(c);
40
39
  });
41
-
42
40
  });
43
41
 
44
42
  // RETAIN
@@ -52,7 +50,7 @@ describe("Retain<T, U> utility", () => {
52
50
  type cases = [
53
51
  Expect<Equal<FooBar, { foo: number; bar: number }>>,
54
52
  Expect<Equal<Baz, { baz: string }>>,
55
- Expect<Equal<FooBaz, { foo: number; baz: string }>>,
53
+ Expect<Equal<FooBaz, { foo: number; baz: string }>>
56
54
  ];
57
55
  const c: cases = [true, true, true];
58
56
  expect(c).toBe(c);
@@ -62,11 +60,8 @@ describe("Retain<T, U> utility", () => {
62
60
  type Obj = { foo: 1; bar?: number; baz: "hi" };
63
61
  type FooBar = Retain<Obj, "foo" | "bar">;
64
62
 
65
- type cases = [
66
- Expect<Equal<FooBar, { foo: 1; bar?: number }>>,
67
- ];
63
+ type cases = [Expect<Equal<FooBar, { foo: 1; bar?: number }>>];
68
64
  const c: cases = [true];
69
65
  expect(c).toBe(c);
70
66
  });
71
-
72
67
  });
@@ -1,3 +1,5 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import type { Includes } from "../src/types";
2
4
  import type { ExpectTrue, ExpectFalse } from "@type-challenges/utils";
3
5
 
@@ -1,3 +1,5 @@
1
+ import { describe, it } from "vitest";
2
+
1
3
  import type { KebabCase } from "../src/types";
2
4
  import type { Expect, Equal } from "@type-challenges/utils";
3
5
 
@@ -1,4 +1,5 @@
1
- /* eslint-disable unicorn/consistent-function-scoping */
1
+ import { describe, it, expect } from "vitest";
2
+
2
3
  import { MutationIdentity } from "../src/Mutation";
3
4
  import type { Expect, Equal, ExpectExtends } from "@type-challenges/utils";
4
5
 
@@ -1,3 +1,5 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import type { PascalCase } from "../src/types";
2
4
  import type { Expect, Equal } from "@type-challenges/utils";
3
5
 
@@ -1,3 +1,5 @@
1
+ import { describe, it } from "vitest";
2
+
1
3
  import type { Pluralize } from "../src/types";
2
4
  import type { Expect, Equal } from "@type-challenges/utils";
3
5
 
@@ -1,3 +1,5 @@
1
+ import { describe, it } from "vitest";
2
+
1
3
  import { SnakeCase } from "../src/types";
2
4
  import { Expect, Equal } from "@type-challenges/utils";
3
5
 
@@ -1,8 +1,9 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Expect, Equal } from "@type-challenges/utils";
2
4
  import { Where, WhereNot } from "../src/types/Where";
3
5
 
4
6
  describe("Where<T,U> and WhereNot<T,U> type utility", () => {
5
-
6
7
  it("readonly string array works correctly", () => {
7
8
  const arr = ["foo", "bar", "baz"] as const;
8
9
  type A = typeof arr;
@@ -11,29 +12,27 @@ describe("Where<T,U> and WhereNot<T,U> type utility", () => {
11
12
 
12
13
  type cases = [
13
14
  //
14
- Expect<Equal<B, "bar"| "baz">>,
15
+ Expect<Equal<B, "bar" | "baz">>,
15
16
  Expect<Equal<F, "foo">>
16
17
  ];
17
-
18
- const c: cases = [ true, true ];
18
+
19
+ const c: cases = [true, true];
19
20
  expect(c).toBe(c);
20
21
  });
21
22
 
22
23
  it("object with literal keys works", () => {
23
- const arr = {foo: true, bar: true, baz: true} as const;
24
+ const arr = { foo: true, bar: true, baz: true } as const;
24
25
  type A = typeof arr;
25
26
  type B = Where<A, `ba${string}`>;
26
27
  type F = WhereNot<A, `ba${string}`>;
27
28
 
28
29
  type cases = [
29
30
  //
30
- Expect<Equal<B, "bar"| "baz">>,
31
+ Expect<Equal<B, "bar" | "baz">>,
31
32
  Expect<Equal<F, "foo">>
32
33
  ];
33
-
34
- const c: cases = [ true, true ];
34
+
35
+ const c: cases = [true, true];
35
36
  expect(c).toBe(c);
36
37
  });
37
-
38
-
39
38
  });
@@ -1,5 +1,7 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { arrayToKeyLookup } from "~/utility";
4
+ import { arrayToKeyLookup } from "../src/utility";
3
5
 
4
6
  describe("arrayToKeyLookup()", () => {
5
7
  it("simple string array is converted", () => {
@@ -8,10 +10,8 @@ describe("arrayToKeyLookup()", () => {
8
10
  expect(lookup.bar).toBe(true);
9
11
  expect(lookup.baz).toBe(true);
10
12
 
11
- type cases = [
12
- Expect<Equal<typeof lookup, Record<"foo" | "bar" | "baz", true>>>
13
- ];
13
+ type cases = [Expect<Equal<typeof lookup, Record<"foo" | "bar" | "baz", true>>>];
14
14
  const cases: cases = [true];
15
15
  expect(cases).toBe(cases);
16
16
  });
17
- });
17
+ });
@@ -1,15 +1,21 @@
1
+ import { describe, it, expect } from "vitest";
1
2
 
2
3
  import { Equal, Expect, ExpectExtends } from "@type-challenges/utils";
3
- import { ArrayConverter, arrayToObject, GeneralDictionary, UniqueDictionary, defineType, keys } from "~/utility";
4
+ import {
5
+ ArrayConverter,
6
+ arrayToObject,
7
+ GeneralDictionary,
8
+ UniqueDictionary,
9
+ defineType,
10
+ keys,
11
+ } from "../src/utility";
4
12
 
5
13
  const foo = { name: "foo", age: 123, color: "red" } as const;
6
14
  const foo2 = { name: "foo", age: 44, color: "orange" } as const;
7
15
  const bar = { name: "bar", age: 456, color: "blue" } as const;
8
16
  const baz = { name: "baz", age: 42, color: "green" } as const;
9
17
 
10
-
11
18
  describe("arrayToObject => ", () => {
12
-
13
19
  it("partial application of arrayToObject()", () => {
14
20
  const t1 = arrayToObject("name", false);
15
21
  type T1 = typeof t1;
@@ -28,7 +34,7 @@ describe("arrayToObject => ", () => {
28
34
  // The response types for each type is as expected
29
35
  Expect<ExpectExtends<GeneralDictionary<"name", any, any>, ReturnType<T1>>>,
30
36
  Expect<ExpectExtends<UniqueDictionary<"name", any, any>, ReturnType<T2>>>,
31
- Expect<ExpectExtends<UniqueDictionary<"name", any, any>, ReturnType<T3>>>,
37
+ Expect<ExpectExtends<UniqueDictionary<"name", any, any>, ReturnType<T3>>>
32
38
  ];
33
39
 
34
40
  const cases: cases = [true, true, true, true, true, true];
@@ -71,7 +77,7 @@ describe("arrayToObject => ", () => {
71
77
  // however when we passed in two "types" for "foo" we get a union
72
78
  Expect<Equal<typeof dict2["foo"], SomeFoo>>,
73
79
  // once we state that foo is not unique, the type expanded to an array
74
- Expect<Equal<typeof dict3["foo"], SomeFoo[]>>,
80
+ Expect<Equal<typeof dict3["foo"], SomeFoo[]>>
75
81
  ];
76
82
  const cases: cases = [true, true, true, true, true];
77
83
  expect(cases).toBe(cases);
@@ -100,12 +106,10 @@ describe("arrayToObject => ", () => {
100
106
  Expect<Equal<Slug["bob"]["slug"], "bob">>,
101
107
  // "age" and "color" are expressed as their widened types
102
108
  Expect<Equal<Id["1"]["age"], number>>,
103
- Expect<Equal<Id["1"]["color"], string>>,
109
+ Expect<Equal<Id["1"]["color"], string>>
104
110
  ];
105
111
 
106
112
  const cases: cases = [true, true, true, true, true, true];
107
113
  expect(cases).toBe(cases);
108
114
  });
109
-
110
-
111
115
  });
@@ -1,3 +1,5 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Expect, Equal } from "@type-challenges/utils";
2
4
  import { Constructor } from "../src/types/Constructor";
3
5
 
@@ -1,5 +1,5 @@
1
- /* eslint-disable unicorn/consistent-function-scoping */
2
- import { createFnWithProps } from "~/index";
1
+ import { describe, it, expect } from "vitest";
2
+ import { createFnWithProps } from "../src/index";
3
3
 
4
4
  describe("createFnWithProps()", () => {
5
5
  it("simple fn and prop are combined, type is retained", () => {
@@ -1,7 +1,8 @@
1
- import type { Expect, Equal } from "@type-challenges/utils";
2
- import { ExpectExtends } from "~/types";
3
- import { defineType } from "~/utility";
1
+ import { describe, it, expect } from "vitest";
4
2
 
3
+ import type { Expect, Equal } from "@type-challenges/utils";
4
+ import { ExpectExtends } from "../src/types";
5
+ import { defineType } from "../src/utility";
5
6
 
6
7
  describe("inferredType() utility", () => {
7
8
  it("only specify a wide type", () => {
@@ -22,7 +23,16 @@ describe("inferredType() utility", () => {
22
23
  Expect<Equal<typeof t, { foo: string; bar: number }>>,
23
24
  // for some odd reason, when we let the default value for literal
24
25
  // we get something odd
25
- Expect<Equal<typeof t2, { foo: string; bar: number;[x: string]: string | number | boolean | symbol | void | object | {} | null | undefined }>>,
26
+ Expect<
27
+ Equal<
28
+ typeof t2,
29
+ {
30
+ foo: string;
31
+ bar: number;
32
+ [x: string]: string | number | boolean | symbol | void | object | {} | null | undefined;
33
+ }
34
+ >
35
+ >,
26
36
  // fortunately it does extend the intended type
27
37
  Expect<ExpectExtends<typeof t2, { foo: string; bar: number }>>
28
38
  ];
@@ -32,9 +42,7 @@ describe("inferredType() utility", () => {
32
42
 
33
43
  it("only specify a literal type", () => {
34
44
  const t = defineType({ foo: 1, bar: "hi" })();
35
- type cases = [
36
- Expect<Equal<typeof t, { foo: 1; bar: "hi" }>>
37
- ];
45
+ type cases = [Expect<Equal<typeof t, { foo: 1; bar: "hi" }>>];
38
46
  const cases: cases = [true];
39
47
  expect(cases).toBe(cases);
40
48
  });
@@ -42,10 +50,8 @@ describe("inferredType() utility", () => {
42
50
  it("specify both wide and literal merged type", () => {
43
51
  const t = defineType({ bar: 1 })({ foo: "" });
44
52
 
45
- type cases = [
46
- Expect<Equal<typeof t, { foo: string; bar: 1 }>>
47
- ];
53
+ type cases = [Expect<Equal<typeof t, { foo: string; bar: 1 }>>];
48
54
  const cases: cases = [true];
49
55
  expect(cases).toBe(cases);
50
56
  });
51
- });
57
+ });
@@ -0,0 +1,43 @@
1
+ import { describe, it } from "vitest";
2
+
3
+ import type { DictPartialApplication } from "src/types";
4
+ import type { Expect, Equal } from "@type-challenges/utils";
5
+
6
+ describe("DictUnwrapValues<T>", () => {
7
+ it("happy path", () => {
8
+ const api = {
9
+ hi: (name: string) => `hi ${name}`,
10
+ bye: (name: string) => `bye ${name}`,
11
+ };
12
+
13
+ type Api = typeof api;
14
+ type T = DictPartialApplication<Api>;
15
+ type Expected = { hi: string; bye: string };
16
+
17
+ type cases = [Expect<Equal<T, Expected>>];
18
+
19
+ const cases: cases = [true];
20
+ });
21
+
22
+ it("object which has non-function based props", () => {
23
+ const api = {
24
+ theAnswer: 42,
25
+ hi: (name: string) => `hi ${name}`,
26
+ bye: (name: string) => `bye ${name}`,
27
+ };
28
+
29
+ type Api = typeof api;
30
+ type T1 = DictPartialApplication<Api>;
31
+ type T2 = DictPartialApplication<Api, true>;
32
+ type T3 = DictPartialApplication<Api, false>;
33
+ type Expected = { hi: string; bye: string };
34
+ type Expected3 = { theAnswer: number; hi: string; bye: string };
35
+
36
+ type cases = [
37
+ Expect<Equal<T1, Expected>>,
38
+ Expect<Equal<T2, Expected>>,
39
+ Expect<Equal<T3, Expected3>>
40
+ ];
41
+ const cases: cases = [true, true, true];
42
+ });
43
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, it } from "vitest";
2
+
3
+ import type { DictReturnValues } from "src/types";
4
+ import type { Expect, Equal } from "@type-challenges/utils";
5
+
6
+ describe("DictReturnValues<T, R, O>", () => {
7
+ it("happy path", () => {
8
+ const api = {
9
+ foo: (name: string) => `${name}`,
10
+ multiply: (v1: number, v2: number) => v1 * v2,
11
+ };
12
+
13
+ type Api = typeof api;
14
+ // convert all functions
15
+ type T1 = DictReturnValues<Api, null>;
16
+ // convert functions with `number` return
17
+ type T2 = DictReturnValues<Api, null, (...args: any[]) => number>;
18
+
19
+ type Expected1 = {
20
+ foo: (name: string) => null;
21
+ multiply: (v1: number, v2: number) => null;
22
+ };
23
+ type Expected2 = {
24
+ foo: (name: string) => string;
25
+ multiply: (v1: number, v2: number) => null;
26
+ };
27
+
28
+ type cases = [Expect<Equal<T1, Expected1>>, Expect<Equal<T2, Expected2>>];
29
+
30
+ const cases: cases = [true, true];
31
+ });
32
+ });
@@ -1,6 +1,8 @@
1
+ import { describe, it, expect } from "vitest";
2
+
1
3
  import { Equal, Expect } from "@type-challenges/utils";
2
- import { Get } from "~/types";
3
- import { defineType } from "~/utility";
4
+ import { Get } from "src/types";
5
+ import { defineType } from "src/utility";
4
6
 
5
7
  describe("Get<T, K> type utility", () => {
6
8
  it("Get<T,K> works with literals and wide types", () => {
@@ -17,7 +19,7 @@ describe("Get<T, K> type utility", () => {
17
19
  Expect<Equal<Id, 1234>>,
18
20
  Expect<Equal<Foo, number>>,
19
21
  Expect<Equal<Bar, string>>,
20
- // non-existant props return never
22
+ // non-existent props return never
21
23
  Expect<Equal<Nada, never>>
22
24
  ];
23
25
  const c: cases = [true, true, true, true];
@@ -0,0 +1,34 @@
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ import type { DictPrependWithFn } from "src/types";
4
+ import type { Expect, Equal } from "@type-challenges/utils";
5
+
6
+ describe("WrapValuesWithFunction<T, R, O>", () => {
7
+ it("happy path", () => {
8
+ const api = {
9
+ static: 42,
10
+ foo: (name: string) => `${name}`,
11
+ multiply: (v1: number, v2: number) => v1 * v2,
12
+ };
13
+
14
+ type Api = typeof api;
15
+ type T1 = DictPrependWithFn<Api, [name: string, age: number]>;
16
+ type T2 = DictPrependWithFn<Api, [name: string, age: number], Function>;
17
+
18
+ type Expected1 = {
19
+ static: (name: string, age: number) => number;
20
+ foo: (name: string, age: number) => (name: string) => string;
21
+ multiply: (name: string, age: number) => (v1: number, v2: number) => number;
22
+ };
23
+
24
+ type Expected2 = {
25
+ static: number;
26
+ foo: (name: string, age: number) => (name: string) => string;
27
+ multiply: (name: string, age: number) => (v1: number, v2: number) => number;
28
+ };
29
+
30
+ type cases = [Expect<Equal<T1, Expected1>>, Expect<Equal<T2, Expected2>>];
31
+ const cases: cases = [true, true];
32
+ expect(cases).toBe(cases);
33
+ });
34
+ });
@@ -0,0 +1,21 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import type { Expect, Equal } from "@type-challenges/utils";
3
+
4
+ import { RequireProps } from "src/types/dictionary";
5
+
6
+ describe("RequireProps<T,R>", () => {
7
+ it("works as expected", () => {
8
+ type Start = { foo?: string; bar?: number };
9
+ type Foo = RequireProps<Start, "foo">;
10
+ type Bar = RequireProps<Start, "bar">;
11
+ type Both = RequireProps<Start, "foo" | "bar">;
12
+
13
+ type cases = [
14
+ Expect<Equal<Foo, { foo: string; bar?: number }>>,
15
+ Expect<Equal<Bar, { foo?: string; bar: number }>>,
16
+ Expect<Equal<Both, { foo: string; bar: number }>>
17
+ ];
18
+ const cases: cases = [true, true, true];
19
+ expect(cases).toBe(cases);
20
+ });
21
+ });
@@ -1,7 +1,7 @@
1
- /* eslint-disable unicorn/consistent-function-scoping */
2
- import { dictionaryTransform, ExplicitFunction } from "~/utility";
1
+ import { describe, it, expect } from "vitest";
2
+ import { dictionaryTransform, ExplicitFunction } from "../src/utility";
3
3
  import { Expect, Equal, NotEqual, ExpectExtends, ExpectFalse } from "@type-challenges/utils";
4
- import { ToFluent, Transformer } from "~/types";
4
+ import { ToFluent, Transformer } from "../src/types";
5
5
 
6
6
  describe("dictionaryTransform()", () => {
7
7
  type A = { foo: string; bar: string };