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.
- package/README.md +1 -1
- package/dist/{index.mjs → index.js} +0 -0
- package/package.json +15 -21
- package/.eslintrc +0 -77
- package/.github/workflows/main.yml +0 -34
- package/.github/workflows/other.yml +0 -15
- package/.nvmrc +0 -1
- package/.prettierrc.js +0 -3
- package/.vscode/launch.json +0 -27
- package/.vscode/settings.json +0 -19
- package/devops/build.js +0 -243
- package/docs/builder-overview.md +0 -45
- package/docs/builder.md +0 -94
- package/src/errors/ReadOnlyViolation.ts +0 -3
- package/src/errors/index.ts +0 -12
- package/src/index.ts +0 -14
- package/src/runtime/README.md +0 -3
- package/src/runtime/api/api.ts +0 -10
- package/src/runtime/api/index.ts +0 -12
- package/src/runtime/builders/Model.ts +0 -25
- package/src/runtime/builders/url.ts +0 -15
- package/src/runtime/combinators/and.ts +0 -15
- package/src/runtime/combinators/filter.ts +0 -267
- package/src/runtime/combinators/index.ts +0 -4
- package/src/runtime/combinators/not.ts +0 -15
- package/src/runtime/combinators/or.ts +0 -5
- package/src/runtime/createFnWithProps.ts +0 -37
- package/src/runtime/dictionary/arrayToKeyLookup.ts +0 -19
- package/src/runtime/dictionary/defineProperties.ts +0 -35
- package/src/runtime/dictionary/dictArr.ts +0 -69
- package/src/runtime/dictionary/dictionaryTransform.ts +0 -22
- package/src/runtime/dictionary/entries.ts +0 -33
- package/src/runtime/dictionary/index.ts +0 -21
- package/src/runtime/dictionary/kv/dictToKv.ts +0 -21
- package/src/runtime/dictionary/kv/filterDictArray.ts +0 -31
- package/src/runtime/dictionary/kv/index.ts +0 -15
- package/src/runtime/dictionary/kv/kv.ts +0 -18
- package/src/runtime/dictionary/kv/kvToDict.ts +0 -24
- package/src/runtime/dictionary/mapTo.ts +0 -206
- package/src/runtime/dictionary/mapValues.ts +0 -23
- package/src/runtime/dictionary/merge.ts +0 -36
- package/src/runtime/dictionary/strArrayToDict.ts +0 -12
- package/src/runtime/index.ts +0 -23
- package/src/runtime/keys.ts +0 -16
- package/src/runtime/lists/asArray.ts +0 -38
- package/src/runtime/lists/createConverter.ts +0 -62
- package/src/runtime/lists/groupBy.ts +0 -15
- package/src/runtime/lists/index.ts +0 -15
- package/src/runtime/literals/ExplicitFunction.ts +0 -10
- package/src/runtime/literals/Suggest.ts +0 -19
- package/src/runtime/literals/arrayToObject.ts +0 -78
- package/src/runtime/literals/box.ts +0 -98
- package/src/runtime/literals/defineType.ts +0 -20
- package/src/runtime/literals/ensureLeading.ts +0 -17
- package/src/runtime/literals/ensureTrailing.ts +0 -17
- package/src/runtime/literals/identity.ts +0 -12
- package/src/runtime/literals/index.ts +0 -23
- package/src/runtime/literals/literal.ts +0 -48
- package/src/runtime/literals/pathJoin.ts +0 -33
- package/src/runtime/literals/stripLeading.ts +0 -15
- package/src/runtime/literals/stripTrailing.ts +0 -15
- package/src/runtime/literals/wide.ts +0 -13
- package/src/runtime/ruleset.ts +0 -42
- package/src/runtime/runtime/README.md +0 -3
- package/src/runtime/runtime/condition.ts +0 -13
- package/src/runtime/runtime/index.ts +0 -16
- package/src/runtime/runtime/type.ts +0 -127
- package/src/runtime/runtime/withValue.ts +0 -39
- package/src/runtime/state/Configurator.ts +0 -76
- package/src/runtime/state/FluentConfigurator.ts +0 -49
- package/src/runtime/state/index.ts +0 -13
- package/src/runtime/type-checks/ifSameType.ts +0 -20
- package/src/runtime/type-checks/ifTypeOf.ts +0 -124
- package/src/runtime/type-checks/index.ts +0 -24
- package/src/runtime/type-checks/isArray.ts +0 -34
- package/src/runtime/type-checks/isBoolean.ts +0 -24
- package/src/runtime/type-checks/isFalse.ts +0 -29
- package/src/runtime/type-checks/isFunction.ts +0 -26
- package/src/runtime/type-checks/isNull.ts +0 -26
- package/src/runtime/type-checks/isNumber.ts +0 -20
- package/src/runtime/type-checks/isObject.ts +0 -22
- package/src/runtime/type-checks/isString.ts +0 -34
- package/src/runtime/type-checks/isSymbol.ts +0 -3
- package/src/runtime/type-checks/isTrue.ts +0 -31
- package/src/runtime/type-checks/isUndefined.ts +0 -33
- package/src/runtime/type-checks/startsWith.ts +0 -107
- package/src/runtime/valueTypes.ts +0 -48
- package/src/types/Api.ts +0 -16
- package/src/types/Constructor.ts +0 -5
- package/src/types/EnumValues.ts +0 -14
- package/src/types/ExpandRecursively.ts +0 -12
- package/src/types/FunctionType.ts +0 -19
- package/src/types/If.ts +0 -10
- package/src/types/Include.ts +0 -18
- package/src/types/KeyedRecord.ts +0 -21
- package/src/types/Keys.ts +0 -26
- package/src/types/Length.ts +0 -8
- package/src/types/Mutable.ts +0 -8
- package/src/types/Narrowable.ts +0 -5
- package/src/types/Not.ts +0 -13
- package/src/types/Numeric.ts +0 -20
- package/src/types/Opaque.ts +0 -11
- package/src/types/README.md +0 -3
- package/src/types/Retain.ts +0 -16
- package/src/types/SimplifyObject.ts +0 -12
- package/src/types/Transformer.ts +0 -15
- package/src/types/TypeGuard.ts +0 -7
- package/src/types/Where.ts +0 -40
- package/src/types/alphabetic/AllCaps.ts +0 -15
- package/src/types/alphabetic/CamelCase.ts +0 -3
- package/src/types/alphabetic/CapFirstAlpha.ts +0 -23
- package/src/types/alphabetic/CapitalizeWords.ts +0 -9
- package/src/types/alphabetic/Cardinality.ts +0 -80
- package/src/types/alphabetic/DashToSnake.ts +0 -3
- package/src/types/alphabetic/DashUppercase.ts +0 -19
- package/src/types/alphabetic/Dasherize.ts +0 -23
- package/src/types/alphabetic/EnsureLeading.ts +0 -24
- package/src/types/alphabetic/EnsureTrailing.ts +0 -24
- package/src/types/alphabetic/HasUppercase.ts +0 -16
- package/src/types/alphabetic/IsCapitalized.ts +0 -18
- package/src/types/alphabetic/KebabCase.ts +0 -13
- package/src/types/alphabetic/LowerAllCaps.ts +0 -5
- package/src/types/alphabetic/PascalCase.ts +0 -29
- package/src/types/alphabetic/PathJoin.ts +0 -54
- package/src/types/alphabetic/Pluralize.ts +0 -112
- package/src/types/alphabetic/SnakeCase.ts +0 -27
- package/src/types/alphabetic/StripLeading.ts +0 -23
- package/src/types/alphabetic/StripTrailing.ts +0 -23
- package/src/types/alphabetic/Url.ts +0 -29
- package/src/types/alphabetic/alpha-characters.ts +0 -81
- package/src/types/alphabetic/index.ts +0 -32
- package/src/types/append-types.ts +0 -10
- package/src/types/boolean-logic/EndsWith.ts +0 -40
- package/src/types/boolean-logic/Extends.ts +0 -22
- package/src/types/boolean-logic/HasParameters.ts +0 -21
- package/src/types/boolean-logic/Includes.ts +0 -33
- package/src/types/boolean-logic/IsLiteral.ts +0 -101
- package/src/types/boolean-logic/IsScalar.ts +0 -20
- package/src/types/boolean-logic/IsUndefined.ts +0 -20
- package/src/types/boolean-logic/Or.ts +0 -12
- package/src/types/boolean-logic/StartsWith.ts +0 -42
- package/src/types/boolean-logic/TypeDefault.ts +0 -58
- package/src/types/boolean-logic/array.ts +0 -57
- package/src/types/boolean-logic/boolean.ts +0 -84
- package/src/types/boolean-logic/equivalency.ts +0 -15
- package/src/types/boolean-logic/index.ts +0 -14
- package/src/types/boolean-logic/object.ts +0 -30
- package/src/types/boolean-logic/string.ts +0 -21
- package/src/types/dictionary/DictChangeValue.ts +0 -34
- package/src/types/dictionary/DictPartialApplication.ts +0 -30
- package/src/types/dictionary/DictPrependWithFn.ts +0 -23
- package/src/types/dictionary/DictReturnValues.ts +0 -27
- package/src/types/dictionary/Get.ts +0 -14
- package/src/types/dictionary/MapTo.ts +0 -428
- package/src/types/dictionary/MutableProps.ts +0 -19
- package/src/types/dictionary/RequireProps.ts +0 -15
- package/src/types/dictionary/SameKeys.ts +0 -11
- package/src/types/dictionary/index.ts +0 -21
- package/src/types/dictionary/props.ts +0 -145
- package/src/types/fluent/fluent.ts +0 -61
- package/src/types/fluent/index.ts +0 -12
- package/src/types/functions/FinalReturn.ts +0 -12
- package/src/types/functions/LogicFunction.ts +0 -4
- package/src/types/functions/index.ts +0 -13
- package/src/types/index.ts +0 -49
- package/src/types/kv/DictFromKv.ts +0 -3
- package/src/types/kv/KeyValue.ts +0 -12
- package/src/types/kv/KvFrom.ts +0 -8
- package/src/types/kv/KvTuple.ts +0 -14
- package/src/types/kv/index.ts +0 -15
- package/src/types/lists/AfterFirst.ts +0 -10
- package/src/types/lists/ConvertAndMap.ts +0 -151
- package/src/types/lists/FilterTuple.ts +0 -20
- package/src/types/lists/First.ts +0 -8
- package/src/types/lists/FirstString.ts +0 -4
- package/src/types/lists/Split.ts +0 -21
- package/src/types/lists/UniqueForProp.ts +0 -18
- package/src/types/lists/index.ts +0 -18
- package/src/types/literal-unions/OptRequired.ts +0 -4
- package/src/types/literal-unions/index.ts +0 -1
- package/src/types/maybe.ts +0 -9
- package/src/types/ruleset-types.ts +0 -76
- package/src/types/runtime.ts +0 -39
- package/src/types/string-literals/Break.ts +0 -22
- package/src/types/string-literals/Concat.ts +0 -9
- package/src/types/string-literals/LeftWhitespace.ts +0 -13
- package/src/types/string-literals/Replace.ts +0 -17
- package/src/types/string-literals/RightWhitespace.ts +0 -13
- package/src/types/string-literals/StringLength.ts +0 -34
- package/src/types/string-literals/Trim.ts +0 -15
- package/src/types/string-literals/TrimLeft.ts +0 -14
- package/src/types/string-literals/TrimRight.ts +0 -14
- package/src/types/string-literals/form-fields.ts +0 -15
- package/src/types/string-literals/index.ts +0 -21
- package/src/types/tuples/DictArray.ts +0 -21
- package/src/types/tuples/FirstKey.ts +0 -10
- package/src/types/tuples/FirstKeyValue.ts +0 -9
- package/src/types/tuples/FirstOfEach.ts +0 -13
- package/src/types/tuples/FromDictArray.ts +0 -14
- package/src/types/tuples/SecondOfEach.ts +0 -13
- package/src/types/tuples/index.ts +0 -17
- package/src/types/type-conversion/TupleToUnion.ts +0 -9
- package/src/types/type-conversion/UnionToIntersection.ts +0 -9
- package/src/types/type-conversion/UnionToTuple.ts +0 -20
- package/src/types/type-conversion/Widen.ts +0 -22
- package/src/types/type-conversion/index.ts +0 -16
- package/src/types/type-testing.ts +0 -14
- package/tests/CamelCase-spec.ts +0 -20
- package/tests/Configurator-spec.hold +0 -106
- package/tests/ExplicitFunction-spec.ts +0 -50
- package/tests/IncludeAndRetain-spec.ts +0 -67
- package/tests/Includes-spec.ts +0 -36
- package/tests/KebabCase-spec.ts +0 -21
- package/tests/PascalCase-spec.ts +0 -22
- package/tests/Pluralize-spec.ts +0 -23
- package/tests/SnakeCase-spec.ts +0 -21
- package/tests/Where.spec.ts +0 -38
- package/tests/arrayToKeyLookup-spec.ts +0 -17
- package/tests/arrayToObject-spec.ts +0 -115
- package/tests/boolean-logic/Contains.test.ts +0 -55
- package/tests/boolean-logic/HasParameters.ts +0 -29
- package/tests/boolean-logic/IsLiteral.spec.ts +0 -65
- package/tests/boolean-logic/boolean.spec.ts +0 -21
- package/tests/boolean-logic/filter.spec.ts +0 -52
- package/tests/constructor.spec.ts +0 -42
- package/tests/createFnWithProps.spec.ts +0 -14
- package/tests/data/SimpleTable.hold +0 -21
- package/tests/data/index.ts +0 -12
- package/tests/data/playlist.hold +0 -25
- package/tests/data/song.hold +0 -23
- package/tests/defineType-spec.ts +0 -57
- package/tests/dictionary/DictChangeValue.test.ts +0 -30
- package/tests/dictionary/DictPartialApplication.test.ts +0 -43
- package/tests/dictionary/DictReturnValues.test.ts +0 -36
- package/tests/dictionary/Get.spec.ts +0 -28
- package/tests/dictionary/IntersectingKeys.test.ts +0 -42
- package/tests/dictionary/MutableProps.test.ts +0 -30
- package/tests/dictionary/OptionalKeys.test.ts +0 -24
- package/tests/dictionary/PrependValuesWithFunction.test.ts +0 -34
- package/tests/dictionary/RequireProps.test.ts +0 -21
- package/tests/dictionary/RequiredKeys.test.ts +0 -53
- package/tests/dictionary/TypeDefault.test.ts +0 -76
- package/tests/dictionary/mapTo.test.ts +0 -388
- package/tests/dictionary/merge.test.ts +0 -41
- package/tests/dictionaryTransform-spec.ts +0 -280
- package/tests/ifTypeOf-spec.ts +0 -191
- package/tests/kv/KeyValue-spec.ts +0 -22
- package/tests/kv/SameKeys-spec.ts +0 -35
- package/tests/kv/dict-to-kv-and-back.spec.ts +0 -169
- package/tests/kv/entries-spec.ts +0 -65
- package/tests/kv/keys.spec.ts +0 -66
- package/tests/kv/kv-spec.ts +0 -20
- package/tests/lists/First.test.ts +0 -43
- package/tests/lists/Length.test.ts +0 -19
- package/tests/lists/Split.test.ts +0 -29
- package/tests/lists/UniqueForProp.spec.ts +0 -59
- package/tests/lists/asArray.test.ts +0 -109
- package/tests/lists/dictArr.test.ts +0 -110
- package/tests/literal-spec.ts +0 -82
- package/tests/literals/AllCaps.spec.ts +0 -33
- package/tests/literals/CamelCase.spec.ts +0 -109
- package/tests/literals/Dasherize.spec.ts +0 -107
- package/tests/literals/EnsureStripLeadingTrailing.test.ts +0 -79
- package/tests/literals/HasUppercase.spec.ts +0 -33
- package/tests/literals/PascalCase.spec.ts +0 -109
- package/tests/literals/PathJoin.test.ts +0 -111
- package/tests/literals/SnakeCase.spec.ts +0 -109
- package/tests/literals/box.test.ts +0 -85
- package/tests/literals/whitespace-capture.spec.ts +0 -60
- package/tests/mapValues-spec.ts +0 -50
- package/tests/props-spec.ts +0 -234
- package/tests/runtime/condition.spec.ts +0 -19
- package/tests/runtime/if-is.spec.ts +0 -390
- package/tests/runtime/map-and-convert.test.ts +0 -31
- package/tests/runtime/type.spec.ts +0 -190
- package/tests/strArrayToDict-spec.ts +0 -40
- package/tests/tuples/TupleToUnion.spec.ts +0 -20
- package/tests/withValue.spec.ts +0 -173
- package/tsconfig.json +0 -36
- package/vitest.config.ts +0 -17
package/tests/Where.spec.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Expect, Equal } from "@type-challenges/utils";
|
|
4
|
-
import { Where, WhereNot } from "../src/types/Where";
|
|
5
|
-
|
|
6
|
-
describe("Where<T,U> and WhereNot<T,U> type utility", () => {
|
|
7
|
-
it("readonly string array works correctly", () => {
|
|
8
|
-
const arr = ["foo", "bar", "baz"] as const;
|
|
9
|
-
type A = typeof arr;
|
|
10
|
-
type B = Where<A, `ba${string}`>;
|
|
11
|
-
type F = WhereNot<A, `ba${string}`>;
|
|
12
|
-
|
|
13
|
-
type cases = [
|
|
14
|
-
//
|
|
15
|
-
Expect<Equal<B, "bar" | "baz">>,
|
|
16
|
-
Expect<Equal<F, "foo">>
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const c: cases = [true, true];
|
|
20
|
-
expect(c).toBe(c);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("object with literal keys works", () => {
|
|
24
|
-
const arr = { foo: true, bar: true, baz: true } as const;
|
|
25
|
-
type A = typeof arr;
|
|
26
|
-
type B = Where<A, `ba${string}`>;
|
|
27
|
-
type F = WhereNot<A, `ba${string}`>;
|
|
28
|
-
|
|
29
|
-
type cases = [
|
|
30
|
-
//
|
|
31
|
-
Expect<Equal<B, "bar" | "baz">>,
|
|
32
|
-
Expect<Equal<F, "foo">>
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const c: cases = [true, true];
|
|
36
|
-
expect(c).toBe(c);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { arrayToKeyLookup } from "../src/runtime";
|
|
5
|
-
|
|
6
|
-
describe("arrayToKeyLookup()", () => {
|
|
7
|
-
it("simple string array is converted", () => {
|
|
8
|
-
const lookup = arrayToKeyLookup("foo", "bar", "baz");
|
|
9
|
-
expect(lookup.foo).toBe(true);
|
|
10
|
-
expect(lookup.bar).toBe(true);
|
|
11
|
-
expect(lookup.baz).toBe(true);
|
|
12
|
-
|
|
13
|
-
type cases = [Expect<Equal<typeof lookup, Record<"foo" | "bar" | "baz", true>>>];
|
|
14
|
-
const cases: cases = [true];
|
|
15
|
-
expect(cases).toBe(cases);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect, ExpectExtends } from "@type-challenges/utils";
|
|
4
|
-
import {
|
|
5
|
-
ArrayConverter,
|
|
6
|
-
arrayToObject,
|
|
7
|
-
GeneralDictionary,
|
|
8
|
-
UniqueDictionary,
|
|
9
|
-
defineType,
|
|
10
|
-
keys,
|
|
11
|
-
} from "../src/runtime";
|
|
12
|
-
|
|
13
|
-
const foo = { name: "foo", age: 123, color: "red" } as const;
|
|
14
|
-
const foo2 = { name: "foo", age: 44, color: "orange" } as const;
|
|
15
|
-
const bar = { name: "bar", age: 456, color: "blue" } as const;
|
|
16
|
-
const baz = { name: "baz", age: 42, color: "green" } as const;
|
|
17
|
-
|
|
18
|
-
describe("arrayToObject => ", () => {
|
|
19
|
-
it("partial application of arrayToObject()", () => {
|
|
20
|
-
const t1 = arrayToObject("name", false);
|
|
21
|
-
type T1 = typeof t1;
|
|
22
|
-
const t2 = arrayToObject("name", true);
|
|
23
|
-
type T2 = typeof t2;
|
|
24
|
-
const t3 = arrayToObject("name");
|
|
25
|
-
type T3 = typeof t3;
|
|
26
|
-
|
|
27
|
-
type cases = [
|
|
28
|
-
// literal statements about uniqueness are conveyed in partial application
|
|
29
|
-
Expect<Equal<T1, ArrayConverter<"name", false>>>,
|
|
30
|
-
Expect<Equal<T2, ArrayConverter<"name", true>>>,
|
|
31
|
-
// the default case is correctly set to true
|
|
32
|
-
Expect<Equal<T3, ArrayConverter<"name", true>>>,
|
|
33
|
-
|
|
34
|
-
// The response types for each type is as expected
|
|
35
|
-
Expect<ExpectExtends<GeneralDictionary<"name", any, any>, ReturnType<T1>>>,
|
|
36
|
-
Expect<ExpectExtends<UniqueDictionary<"name", any, any>, ReturnType<T2>>>,
|
|
37
|
-
Expect<ExpectExtends<UniqueDictionary<"name", any, any>, ReturnType<T3>>>
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
const cases: cases = [true, true, true, true, true, true];
|
|
41
|
-
expect(cases).toBe(cases);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("arrayToObject() is able to operate on unique and non-unique types", () => {
|
|
45
|
-
// first test where name is unique
|
|
46
|
-
const arr1 = [foo, bar, baz];
|
|
47
|
-
const dict1 = arrayToObject("name")(arr1);
|
|
48
|
-
|
|
49
|
-
expect(dict1.foo).toBe(foo);
|
|
50
|
-
expect(dict1.bar).toBe(bar);
|
|
51
|
-
expect(dict1.baz).toBe(baz);
|
|
52
|
-
|
|
53
|
-
// now test where name is not unique
|
|
54
|
-
const arr2 = [foo, foo2, bar, baz];
|
|
55
|
-
const dict2 = arrayToObject("name")(arr2);
|
|
56
|
-
|
|
57
|
-
expect(dict2.foo).toBe(foo2);
|
|
58
|
-
expect(dict2.bar).toBe(bar);
|
|
59
|
-
expect(dict2.baz).toBe(baz);
|
|
60
|
-
|
|
61
|
-
// because we've stated that items are _not_ unique
|
|
62
|
-
// we should expect results to be an array
|
|
63
|
-
const dict3 = arrayToObject("name", false)(arr2);
|
|
64
|
-
|
|
65
|
-
expect(Array.isArray(dict3.foo)).toBe(true);
|
|
66
|
-
expect(Array.isArray(dict3.bar)).toBe(true);
|
|
67
|
-
expect(Array.isArray(dict3.baz)).toBe(true);
|
|
68
|
-
|
|
69
|
-
type SomeFoo = typeof foo | typeof foo2;
|
|
70
|
-
|
|
71
|
-
type cases = [
|
|
72
|
-
// both unique and non-unique have the same keys
|
|
73
|
-
Expect<Equal<keyof typeof dict1, "foo" | "bar" | "baz">>,
|
|
74
|
-
Expect<Equal<keyof typeof dict2, "foo" | "bar" | "baz">>,
|
|
75
|
-
// with a unique type for "foo" we get a literal definition
|
|
76
|
-
Expect<Equal<typeof dict1["foo"], typeof foo>>,
|
|
77
|
-
// however when we passed in two "types" for "foo" we get a union
|
|
78
|
-
Expect<Equal<typeof dict2["foo"], SomeFoo>>,
|
|
79
|
-
// once we state that foo is not unique, the type expanded to an array
|
|
80
|
-
Expect<Equal<typeof dict3["foo"], SomeFoo[]>>
|
|
81
|
-
];
|
|
82
|
-
const cases: cases = [true, true, true, true, true];
|
|
83
|
-
expect(cases).toBe(cases);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("type support of wide an narrow types", () => {
|
|
87
|
-
const r1 = defineType({ id: 1, slug: "bob" })({ age: 45, color: "blue" });
|
|
88
|
-
const r2 = defineType({ id: 2, slug: "chris" })({ age: 23, color: "red" });
|
|
89
|
-
const arr = [r1, r2];
|
|
90
|
-
|
|
91
|
-
const id = arrayToObject("id")(arr);
|
|
92
|
-
type Id = typeof id;
|
|
93
|
-
const slug = arrayToObject("slug")(arr);
|
|
94
|
-
type Slug = typeof slug;
|
|
95
|
-
|
|
96
|
-
expect(keys(id)).toContain("1");
|
|
97
|
-
expect(keys(id)).toContain("2");
|
|
98
|
-
expect(keys(slug)).toContain("bob");
|
|
99
|
-
expect(keys(slug)).toContain("chris");
|
|
100
|
-
|
|
101
|
-
type cases = [
|
|
102
|
-
// "id" and "slug" are always expressed as literals
|
|
103
|
-
Expect<Equal<Id["1"]["id"], 1>>,
|
|
104
|
-
Expect<Equal<Id["1"]["slug"], "bob">>,
|
|
105
|
-
Expect<Equal<Slug["bob"]["id"], 1>>,
|
|
106
|
-
Expect<Equal<Slug["bob"]["slug"], "bob">>,
|
|
107
|
-
// "age" and "color" are expressed as their widened types
|
|
108
|
-
Expect<Equal<Id["1"]["age"], number>>,
|
|
109
|
-
Expect<Equal<Id["1"]["color"], string>>
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
const cases: cases = [true, true, true, true, true, true];
|
|
113
|
-
expect(cases).toBe(cases);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
2
|
-
import { Contains, NarrowlyContains } from "src/types/boolean-logic/array";
|
|
3
|
-
import { describe, it } from "vitest";
|
|
4
|
-
|
|
5
|
-
describe("Contains<T,A>", () => {
|
|
6
|
-
it("happy-path", () => {
|
|
7
|
-
type T1 = [number, 32, 64, "foo"];
|
|
8
|
-
type T2 = [false, true];
|
|
9
|
-
type T3 = [42, 64, 128];
|
|
10
|
-
type T4 = ["foo", "bar"];
|
|
11
|
-
|
|
12
|
-
type cases = [
|
|
13
|
-
// "foo" extends string so true
|
|
14
|
-
Expect<Equal<Contains<string, T1>, true>>,
|
|
15
|
-
// "bar" does NOT extend "foo"
|
|
16
|
-
Expect<Equal<Contains<"bar", T1>, false>>,
|
|
17
|
-
// T4 has literal string but this will match the wide type string
|
|
18
|
-
Expect<Equal<Contains<string, T4>, true>>,
|
|
19
|
-
// T1 has both wide and narrow versions of "number"
|
|
20
|
-
Expect<Equal<Contains<number, T1>, true>>,
|
|
21
|
-
// T3 has narrow versions of "number"
|
|
22
|
-
Expect<Equal<Contains<number, T3>, true>>,
|
|
23
|
-
// boolean literals evaluate to wide type
|
|
24
|
-
Expect<Equal<Contains<boolean, T2>, true>>
|
|
25
|
-
];
|
|
26
|
-
const cases: cases = [true, true, true, true, true, true];
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("NarrowlyContains<T,A>", () => {
|
|
31
|
-
it("happy-path", () => {
|
|
32
|
-
type T1 = [number, 32, 64, "foo"];
|
|
33
|
-
type T2 = [false, true];
|
|
34
|
-
type T3 = [42, 64, 128];
|
|
35
|
-
type T4 = ["foo", "bar"];
|
|
36
|
-
|
|
37
|
-
type cases = [
|
|
38
|
-
// "foo" is not equal to string
|
|
39
|
-
Expect<Equal<NarrowlyContains<string, T1>, false>>,
|
|
40
|
-
// "foo" does equal "foo"
|
|
41
|
-
Expect<Equal<NarrowlyContains<"foo", T1>, true>>,
|
|
42
|
-
// T4 has literal string but this doesn't match with NarrowlyContains
|
|
43
|
-
Expect<Equal<NarrowlyContains<string, T4>, false>>,
|
|
44
|
-
// T1 has both wide and narrow versions of "number" but match is only on wide type
|
|
45
|
-
Expect<Equal<NarrowlyContains<number, T1>, true>>,
|
|
46
|
-
// T3 has matches on narrow number
|
|
47
|
-
Expect<Equal<NarrowlyContains<42, T3>, true>>,
|
|
48
|
-
// T3 identifies a non-match of narrow numbers
|
|
49
|
-
Expect<Equal<NarrowlyContains<442, T3>, false>>,
|
|
50
|
-
// boolean literals evaluate to wide type
|
|
51
|
-
Expect<Equal<NarrowlyContains<boolean, T2>, false>>
|
|
52
|
-
];
|
|
53
|
-
const cases: cases = [true, true, true, true, true, true, true];
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
2
|
-
import { HasParameters } from "src/types";
|
|
3
|
-
import { describe, it } from "vitest";
|
|
4
|
-
|
|
5
|
-
// Note: type tests fail visible inspection but 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("HasParameters<T>", () => {
|
|
10
|
-
it("happy path", () => {
|
|
11
|
-
const fn1 = (foo: string) => `${foo}bar`;
|
|
12
|
-
const fn2 = (foo: string) => `${foo}bar` as const;
|
|
13
|
-
const fn3 = () => `hello world`;
|
|
14
|
-
const fn4 = () => `hello world` as const;
|
|
15
|
-
const fn5 = (r: string, g: string, b: string) => `${r},${g},${b}` as const;
|
|
16
|
-
|
|
17
|
-
type cases = [
|
|
18
|
-
// single
|
|
19
|
-
Expect<Equal<HasParameters<typeof fn1>, true>>,
|
|
20
|
-
Expect<Equal<HasParameters<typeof fn2>, true>>,
|
|
21
|
-
// none
|
|
22
|
-
Expect<Equal<HasParameters<typeof fn3>, false>>,
|
|
23
|
-
Expect<Equal<HasParameters<typeof fn4>, false>>,
|
|
24
|
-
// multiple
|
|
25
|
-
Expect<Equal<HasParameters<typeof fn5>, true>>
|
|
26
|
-
];
|
|
27
|
-
const cases: cases = [true, true, true, true, true];
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
3
|
-
import { IsBooleanLiteral, IsLiteral, IsOptionalLiteral } from "src/types";
|
|
4
|
-
|
|
5
|
-
describe("IsLiteral<T> type utility", () => {
|
|
6
|
-
it("string values", () => {
|
|
7
|
-
const s = "hi" as string;
|
|
8
|
-
const sl = "hi" as const;
|
|
9
|
-
|
|
10
|
-
type cases = [
|
|
11
|
-
Expect<Equal<IsLiteral<typeof s>, false>>,
|
|
12
|
-
Expect<Equal<IsLiteral<typeof sl>, true>>
|
|
13
|
-
];
|
|
14
|
-
const cases: cases = [true, true];
|
|
15
|
-
expect(typeof s).toBe("string");
|
|
16
|
-
expect(typeof sl).toBe("string");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("numeric values", () => {
|
|
20
|
-
const v = 42 as number;
|
|
21
|
-
const vl = 42 as const;
|
|
22
|
-
|
|
23
|
-
type cases = [
|
|
24
|
-
Expect<Equal<IsLiteral<typeof v>, false>>,
|
|
25
|
-
Expect<Equal<IsLiteral<typeof vl>, true>>
|
|
26
|
-
];
|
|
27
|
-
const cases: cases = [true, true];
|
|
28
|
-
|
|
29
|
-
expect(typeof v).toBe("number");
|
|
30
|
-
expect(typeof vl).toBe("number");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("boolean values", () => {
|
|
34
|
-
const v = true as boolean;
|
|
35
|
-
const vl = false as const;
|
|
36
|
-
|
|
37
|
-
type cases = [
|
|
38
|
-
// wide
|
|
39
|
-
Expect<Equal<IsBooleanLiteral<typeof v>, false>>,
|
|
40
|
-
Expect<Equal<IsLiteral<typeof v>, false>>,
|
|
41
|
-
// literal
|
|
42
|
-
Expect<Equal<IsBooleanLiteral<typeof vl>, true>>,
|
|
43
|
-
Expect<Equal<IsLiteral<typeof vl>, true>>
|
|
44
|
-
];
|
|
45
|
-
const cases: cases = [true, true, true, true];
|
|
46
|
-
expect(typeof v).toBe("boolean");
|
|
47
|
-
expect(typeof vl).toBe("boolean");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("union with undefined", () => {
|
|
51
|
-
const vb = true as true | undefined;
|
|
52
|
-
const vs = "foo" as "foo" | undefined;
|
|
53
|
-
const vn = 42 as 42 | undefined;
|
|
54
|
-
|
|
55
|
-
type cases = [
|
|
56
|
-
Expect<Equal<IsLiteral<Exclude<typeof vb, undefined>>, true>>, //
|
|
57
|
-
Expect<Equal<IsLiteral<Exclude<typeof vs, undefined>>, true>>, //
|
|
58
|
-
Expect<Equal<IsLiteral<Exclude<typeof vn, undefined>>, true>>, //
|
|
59
|
-
Expect<Equal<IsOptionalLiteral<typeof vb>, true>>, //
|
|
60
|
-
Expect<Equal<IsOptionalLiteral<typeof vs>, true>>, //
|
|
61
|
-
Expect<Equal<IsOptionalLiteral<typeof vn>, true>> //
|
|
62
|
-
];
|
|
63
|
-
const cases: cases = [true, true, true, true, true, true];
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
// import type { Equal, Expect } from "@type-challenges/utils";
|
|
3
|
-
import { and, filter } from "src/runtime";
|
|
4
|
-
|
|
5
|
-
describe("boolean logic", () => {
|
|
6
|
-
it("AND operation", () => {
|
|
7
|
-
const a1 = and(
|
|
8
|
-
() => true,
|
|
9
|
-
() => false
|
|
10
|
-
);
|
|
11
|
-
const a2 = and(
|
|
12
|
-
() => true,
|
|
13
|
-
() => true
|
|
14
|
-
);
|
|
15
|
-
const md = and(filter({ endsWith: ".md" }), filter({ not: { startsWith: "_" } }));
|
|
16
|
-
|
|
17
|
-
expect(a1()).toBe(false);
|
|
18
|
-
expect(a2()).toBe(true);
|
|
19
|
-
expect(["foo.md", "bar.html", "_baz.md"].filter(md)).toEqual(["foo.md"]);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { filter } from "src/runtime";
|
|
2
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
3
|
-
import { describe, it, expect } from "vitest";
|
|
4
|
-
|
|
5
|
-
describe("filter() utility function", () => {
|
|
6
|
-
it("string filter built and gives proper types", () => {
|
|
7
|
-
const f = filter({ startsWith: "th" });
|
|
8
|
-
type P = Parameters<typeof f>;
|
|
9
|
-
type R = ReturnType<typeof f>;
|
|
10
|
-
const notPrivate = filter({ not: { startsWith: ["_", "."] } });
|
|
11
|
-
|
|
12
|
-
// runtime
|
|
13
|
-
expect(typeof f).toEqual("function");
|
|
14
|
-
expect(["one", "two", "three"].filter(f)).toEqual(["three"]);
|
|
15
|
-
expect(["foo.md", "bar.html", "_private.md", ".bobs-your-uncle.txt"].filter(notPrivate)) //
|
|
16
|
-
.toEqual(["foo.md", "bar.html"]);
|
|
17
|
-
|
|
18
|
-
// design time
|
|
19
|
-
type cases = [
|
|
20
|
-
Expect<Equal<P[0], string | undefined>>, //
|
|
21
|
-
Expect<Equal<R, boolean>>
|
|
22
|
-
];
|
|
23
|
-
const cases: cases = [true, true];
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("numeric filter built and gives proper types", () => {
|
|
27
|
-
const f = filter({ equals: 42 });
|
|
28
|
-
type P = Parameters<typeof f>;
|
|
29
|
-
type R = ReturnType<typeof f>;
|
|
30
|
-
|
|
31
|
-
// runtime
|
|
32
|
-
expect(typeof f).toEqual("function");
|
|
33
|
-
expect([1, 2, 3, 4, 5].filter(filter({ greaterThan: 3 }))) //
|
|
34
|
-
.toEqual([4, 5]);
|
|
35
|
-
expect([1, 2, 3, 4, 5].filter(filter({ not: { greaterThan: 3 } }))) //
|
|
36
|
-
.toEqual([1, 2, 3]);
|
|
37
|
-
|
|
38
|
-
// design time
|
|
39
|
-
type cases = [
|
|
40
|
-
Expect<Equal<P[0], number | undefined>>, //
|
|
41
|
-
Expect<Equal<R, boolean>>
|
|
42
|
-
];
|
|
43
|
-
const cases: cases = [true, true];
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("string filter's startsWith", () => {
|
|
47
|
-
const f = filter({ startsWith: "." });
|
|
48
|
-
const remaining = ["foo", "bar", ".baz"].filter(f);
|
|
49
|
-
|
|
50
|
-
expect(remaining).toEqual([".baz"]);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Expect, Equal } from "@type-challenges/utils";
|
|
4
|
-
import { Constructor } from "../src/types/Constructor";
|
|
5
|
-
|
|
6
|
-
class TestClass {
|
|
7
|
-
public foo: number;
|
|
8
|
-
public bar: string;
|
|
9
|
-
|
|
10
|
-
constructor(foo: number, bar: string) {
|
|
11
|
-
this.foo = foo;
|
|
12
|
-
this.bar = bar;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("Constructor<Ctor, Klass>", () => {
|
|
17
|
-
it("simple test", () => {
|
|
18
|
-
type KlassParams = ConstructorParameters<typeof TestClass>;
|
|
19
|
-
type KlassInstance = InstanceType<typeof TestClass>;
|
|
20
|
-
type Synthetic = Constructor<[foo: number, bar: string], TestClass>;
|
|
21
|
-
type SynReturn = InstanceType<Synthetic>;
|
|
22
|
-
const s: Synthetic = TestClass;
|
|
23
|
-
|
|
24
|
-
const myS = new s(1, "bar");
|
|
25
|
-
|
|
26
|
-
const inst = new TestClass(1, "bar");
|
|
27
|
-
type Instance = typeof inst;
|
|
28
|
-
|
|
29
|
-
type cases = [
|
|
30
|
-
// prep
|
|
31
|
-
Expect<Equal<Instance, { foo: number; bar: string }>>,
|
|
32
|
-
Expect<Equal<Instance, KlassInstance>>,
|
|
33
|
-
Expect<Equal<KlassParams, [foo: number, bar: string]>>,
|
|
34
|
-
//
|
|
35
|
-
Expect<Equal<SynReturn, TestClass>>
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const c: cases = [true, true, true, true];
|
|
39
|
-
expect(c).toBe(c);
|
|
40
|
-
expect(myS).toBeInstanceOf(TestClass);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createFnWithProps } from "../src/index";
|
|
3
|
-
|
|
4
|
-
describe("createFnWithProps()", () => {
|
|
5
|
-
it("simple fn and prop are combined, type is retained", () => {
|
|
6
|
-
const fn = () => "hi";
|
|
7
|
-
const props = { foo: "bar" };
|
|
8
|
-
/** combo */
|
|
9
|
-
const combo = createFnWithProps(fn, props);
|
|
10
|
-
|
|
11
|
-
expect(combo.foo).toBe("bar");
|
|
12
|
-
expect(combo()).toBe("hi");
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IoModel } from "~/utility";
|
|
2
|
-
|
|
3
|
-
export interface ISimpleTable<T extends {}, S extends Readonly<string>> {
|
|
4
|
-
name: S;
|
|
5
|
-
is: IoModel<T, S>["is"];
|
|
6
|
-
encode: IoModel<T, S>["encode"];
|
|
7
|
-
decode: IoModel<T, S>["decode"];
|
|
8
|
-
select: (...cols: Array<keyof T> | ["*"]) => string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const SimpleTable = <T extends {}, S extends Readonly<string>>(
|
|
12
|
-
model: IoModel<T, S>
|
|
13
|
-
): ISimpleTable<T, S> => {
|
|
14
|
-
return {
|
|
15
|
-
name: model.name,
|
|
16
|
-
is: model.is,
|
|
17
|
-
encode: model.encode,
|
|
18
|
-
decode: model.decode,
|
|
19
|
-
select: (..._cols: Array<keyof T> | ["*"]) => `You did it`,
|
|
20
|
-
};
|
|
21
|
-
};
|
package/tests/data/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// #autoindex
|
|
2
|
-
|
|
3
|
-
// #region auto-indexed files
|
|
4
|
-
// index last changed at: 8th Aug, 2022, 06:09 PM ( GMT-7 )
|
|
5
|
-
// hash-code: 683d9860
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// #endregion auto-indexed files
|
|
10
|
-
|
|
11
|
-
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
12
|
-
// for more info
|
package/tests/data/playlist.hold
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import * as D from "io-ts/Decoder";
|
|
3
|
-
import { IoModel } from "~/utility";
|
|
4
|
-
|
|
5
|
-
export const PlaylistRequired = {
|
|
6
|
-
/** name of the playlist */
|
|
7
|
-
name: t.string,
|
|
8
|
-
/** description of the playlist */
|
|
9
|
-
description: t.string,
|
|
10
|
-
};
|
|
11
|
-
export const PlaylistOptional = {
|
|
12
|
-
/** artists included in the playlist */
|
|
13
|
-
artists: t.array(t.string),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const PlaylistIoTs = t.intersection([t.type(PlaylistRequired), t.partial(PlaylistOptional)]);
|
|
17
|
-
export type IPlaylistIoTs = t.TypeOf<typeof PlaylistIoTs>;
|
|
18
|
-
|
|
19
|
-
export const Playlist = IoModel("Playlist", PlaylistRequired, PlaylistOptional);
|
|
20
|
-
|
|
21
|
-
export const Person = D.struct({
|
|
22
|
-
/** a person's name */
|
|
23
|
-
name: D.string,
|
|
24
|
-
age: D.number,
|
|
25
|
-
});
|
package/tests/data/song.hold
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
import { IoModel } from "~/utility";
|
|
3
|
-
|
|
4
|
-
export const SongMeta = t.partial({ year: t.number, genre: t.string });
|
|
5
|
-
export const Song_RequiredProps = {
|
|
6
|
-
song: t.string,
|
|
7
|
-
artist: t.string,
|
|
8
|
-
};
|
|
9
|
-
export const Song_OptionalProps = {
|
|
10
|
-
/** the album which the song is featured in */
|
|
11
|
-
album: t.string,
|
|
12
|
-
/** the four digit year -- YYYY -- the song was released */
|
|
13
|
-
meta: SongMeta,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const Song = IoModel("Song", Song_RequiredProps, Song_OptionalProps);
|
|
17
|
-
export type ISong = t.TypeOf<typeof Song>;
|
|
18
|
-
export const mySong: ISong = {
|
|
19
|
-
artist: "Billy Idol",
|
|
20
|
-
song: "Whiplash Smile",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const Songs = t.array(Song);
|
package/tests/defineType-spec.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
4
|
-
import { ExpectExtends } from "../src/types";
|
|
5
|
-
import { defineType } from "../src/runtime";
|
|
6
|
-
|
|
7
|
-
describe("inferredType() utility", () => {
|
|
8
|
-
it("only specify a wide type", () => {
|
|
9
|
-
const t = defineType({})({ foo: "", bar: 0 });
|
|
10
|
-
|
|
11
|
-
expect(t.foo).toBe("");
|
|
12
|
-
expect(t.bar).toBe(0);
|
|
13
|
-
|
|
14
|
-
// TODO: see if we can eliminate this difference
|
|
15
|
-
// between t and t2 though it is not impactful
|
|
16
|
-
const t2 = defineType()({ foo: "", bar: 0 });
|
|
17
|
-
|
|
18
|
-
expect(t2.foo).toBe("");
|
|
19
|
-
expect(t2.bar).toBe(0);
|
|
20
|
-
|
|
21
|
-
type cases = [
|
|
22
|
-
// when we provide {} as a literal type; we get the expected type
|
|
23
|
-
Expect<Equal<typeof t, { foo: string; bar: number }>>,
|
|
24
|
-
// for some odd reason, when we let the default value for literal
|
|
25
|
-
// we get something odd
|
|
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
|
-
>,
|
|
36
|
-
// fortunately it does extend the intended type
|
|
37
|
-
Expect<ExpectExtends<typeof t2, { foo: string; bar: number }>>
|
|
38
|
-
];
|
|
39
|
-
const cases: cases = [true, true, true];
|
|
40
|
-
expect(cases).toBe(cases);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("only specify a literal type", () => {
|
|
44
|
-
const t = defineType({ foo: 1, bar: "hi" })();
|
|
45
|
-
type cases = [Expect<Equal<typeof t, { foo: 1; bar: "hi" }>>];
|
|
46
|
-
const cases: cases = [true];
|
|
47
|
-
expect(cases).toBe(cases);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("specify both wide and literal merged type", () => {
|
|
51
|
-
const t = defineType({ bar: 1 })({ foo: "" });
|
|
52
|
-
|
|
53
|
-
type cases = [Expect<Equal<typeof t, { foo: string; bar: 1 }>>];
|
|
54
|
-
const cases: cases = [true];
|
|
55
|
-
expect(cases).toBe(cases);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
3
|
-
import { DictChangeValue } from "../../src/types/dictionary/DictChangeValue";
|
|
4
|
-
import { SimplifyObject } from "../../src/types/SimplifyObject";
|
|
5
|
-
|
|
6
|
-
const test_obj = {
|
|
7
|
-
foo: "hello world",
|
|
8
|
-
bar: 42,
|
|
9
|
-
baz: () => "that's all folks",
|
|
10
|
-
} as const;
|
|
11
|
-
type TestObj = typeof test_obj;
|
|
12
|
-
|
|
13
|
-
describe("DictChangeValue", () => {
|
|
14
|
-
it("convert all KVs to a single value type", () => {
|
|
15
|
-
type T = DictChangeValue<TestObj, number>;
|
|
16
|
-
|
|
17
|
-
type cases = [Expect<Equal<T, { foo: number; bar: number; baz: number }>>];
|
|
18
|
-
const cases: cases = [true];
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("convert functions values to boolean", () => {
|
|
22
|
-
type F = DictChangeValue<TestObj, boolean, Function>;
|
|
23
|
-
type S = DictChangeValue<TestObj, string, string>;
|
|
24
|
-
type N = DictChangeValue<TestObj, number, number>;
|
|
25
|
-
type T = SimplifyObject<F & S & N>;
|
|
26
|
-
|
|
27
|
-
type cases = [Expect<Equal<T, { foo: string; bar: number; baz: boolean }>>];
|
|
28
|
-
const cases: cases = [true];
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
});
|