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
|
@@ -1,36 +0,0 @@
|
|
|
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 = [
|
|
29
|
-
//
|
|
30
|
-
Expect<Equal<T1, Expected1>>,
|
|
31
|
-
Expect<Equal<T2, Expected2>>
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
const cases: cases = [true, true];
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
4
|
-
import { Get } from "src/types";
|
|
5
|
-
import { defineType } from "src/runtime";
|
|
6
|
-
|
|
7
|
-
describe("Get<T, K> type utility", () => {
|
|
8
|
-
it("Get<T,K> works with literals and wide types", () => {
|
|
9
|
-
const input = defineType({ id: 1234 })({ foo: 1, bar: "hi" });
|
|
10
|
-
type Input = typeof input;
|
|
11
|
-
|
|
12
|
-
type Id = Get<Input, "id">;
|
|
13
|
-
type Foo = Get<Input, "foo">;
|
|
14
|
-
type Bar = Get<Input, "bar">;
|
|
15
|
-
type Nada = Get<Input, "nada">;
|
|
16
|
-
|
|
17
|
-
type cases = [
|
|
18
|
-
// valid props are pulled off
|
|
19
|
-
Expect<Equal<Id, 1234>>,
|
|
20
|
-
Expect<Equal<Foo, number>>,
|
|
21
|
-
Expect<Equal<Bar, string>>,
|
|
22
|
-
// non-existent props return never
|
|
23
|
-
Expect<Equal<Nada, never>>
|
|
24
|
-
];
|
|
25
|
-
const c: cases = [true, true, true, true];
|
|
26
|
-
expect(c).toBe(c);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
4
|
-
import { IntersectingKeys } from "src/types/dictionary";
|
|
5
|
-
|
|
6
|
-
describe("IntersectingKeys<T,U>", () => {
|
|
7
|
-
it("with overlap", () => {
|
|
8
|
-
type T = { foo: string; bar: number; baz: any };
|
|
9
|
-
type U = { foo: string; bar: number };
|
|
10
|
-
type V = IntersectingKeys<T, U>;
|
|
11
|
-
|
|
12
|
-
type cases = [Expect<Equal<V, "foo" | "bar">>];
|
|
13
|
-
const cases: cases = [true];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("no overlap", () => {
|
|
17
|
-
type T = { foo1: string; bar1: number; baz1: any };
|
|
18
|
-
type U = { foo: string; bar: number };
|
|
19
|
-
type V = IntersectingKeys<T, U>;
|
|
20
|
-
type VU = Exclude<U, V>;
|
|
21
|
-
|
|
22
|
-
type cases = [
|
|
23
|
-
// intersection is "never"
|
|
24
|
-
Expect<Equal<VU, U>>,
|
|
25
|
-
// Excluding "never" results in no change
|
|
26
|
-
Expect<Equal<VU, U>>
|
|
27
|
-
];
|
|
28
|
-
const cases: cases = [true, true];
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("using string[] instead of object", () => {
|
|
32
|
-
type T = { foo: string; bar: number; baz: any };
|
|
33
|
-
type U = readonly ["foo", "bart"];
|
|
34
|
-
type V = IntersectingKeys<T, U>;
|
|
35
|
-
|
|
36
|
-
type cases = [
|
|
37
|
-
//
|
|
38
|
-
Expect<Equal<V, "foo">>
|
|
39
|
-
];
|
|
40
|
-
const cases: cases = [true];
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
3
|
-
|
|
4
|
-
import { MutableProps } from "src/types/dictionary";
|
|
5
|
-
|
|
6
|
-
describe("MutableProps<T,M>", () => {
|
|
7
|
-
it("works as expected", () => {
|
|
8
|
-
type Test = { foo: string; bar?: number; baz: Readonly<boolean> };
|
|
9
|
-
type Foo = MutableProps<Test, "foo" | "bar">;
|
|
10
|
-
type Bar = MutableProps<Test, "bar">;
|
|
11
|
-
type FooBar = MutableProps<Test, "foo" | "bar">;
|
|
12
|
-
type FooBaz = MutableProps<Test, "foo" | "baz">;
|
|
13
|
-
|
|
14
|
-
type cases = [
|
|
15
|
-
Expect<Equal<Foo, { foo: string; bar?: Readonly<number>; readonly baz: Readonly<boolean> }>>,
|
|
16
|
-
Expect<
|
|
17
|
-
Equal<
|
|
18
|
-
Bar,
|
|
19
|
-
{ readonly foo: Readonly<string>; bar?: number; readonly baz: Readonly<boolean> }
|
|
20
|
-
>
|
|
21
|
-
>,
|
|
22
|
-
Expect<Equal<FooBar, { foo: string; bar?: number; readonly baz: Readonly<boolean> }>>,
|
|
23
|
-
Expect<
|
|
24
|
-
Equal<FooBaz, { foo: string; readonly bar?: Readonly<number>; baz: Readonly<boolean> }>
|
|
25
|
-
>
|
|
26
|
-
];
|
|
27
|
-
const cases: cases = [true, true, true, true];
|
|
28
|
-
expect(cases).toBe(cases);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
3
|
-
import { OptionalKeys } from "src/types/dictionary";
|
|
4
|
-
|
|
5
|
-
type Test = { title: string; value: number; color?: string };
|
|
6
|
-
|
|
7
|
-
describe("OptionalKeys<T, V>", () => {
|
|
8
|
-
it("basic usage without filtering on value", () => {
|
|
9
|
-
type T = OptionalKeys<Test>;
|
|
10
|
-
|
|
11
|
-
type cases = [Expect<Equal<T, "color">>];
|
|
12
|
-
const cases: cases = [true];
|
|
13
|
-
expect(cases).toBe(cases);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("basic usage with a value filter", () => {
|
|
17
|
-
type T1 = OptionalKeys<Test, string>;
|
|
18
|
-
type T2 = OptionalKeys<Test, number>;
|
|
19
|
-
|
|
20
|
-
type cases = [Expect<Equal<T1, "color">>, Expect<Equal<T2, never>>];
|
|
21
|
-
const cases: cases = [true, true];
|
|
22
|
-
expect(cases).toBe(cases);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
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,53 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import type { Expect, Equal } from "@type-challenges/utils";
|
|
3
|
-
import { RequiredKeys } from "src/types/dictionary";
|
|
4
|
-
import { First, Narrowable } from "src";
|
|
5
|
-
|
|
6
|
-
type Test = { title: string; value: number; color?: string };
|
|
7
|
-
|
|
8
|
-
describe("RequiredKeys<T, V>", () => {
|
|
9
|
-
it("basic usage without filtering on value", () => {
|
|
10
|
-
type T = RequiredKeys<Test>;
|
|
11
|
-
|
|
12
|
-
type cases = [Expect<Equal<T, "title" | "value">>];
|
|
13
|
-
const cases: cases = [true];
|
|
14
|
-
expect(cases).toBe(cases);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("basic usage with a value filter", () => {
|
|
18
|
-
type T1 = RequiredKeys<Test, string>;
|
|
19
|
-
type T2 = RequiredKeys<Test, number>;
|
|
20
|
-
|
|
21
|
-
type cases = [Expect<Equal<T1, "title">>, Expect<Equal<T2, "value">>];
|
|
22
|
-
const cases: cases = [true, true];
|
|
23
|
-
expect(cases).toBe(cases);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("typed explicitly", () => {
|
|
27
|
-
type O = {
|
|
28
|
-
id: number;
|
|
29
|
-
name: string;
|
|
30
|
-
title: string;
|
|
31
|
-
cost?: number;
|
|
32
|
-
color?: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const genericArr: O[] = [
|
|
36
|
-
{ id: 1, name: "foo", title: "one", cost: 15 },
|
|
37
|
-
{ id: 2, name: "bar", title: "one" },
|
|
38
|
-
{ id: 3, name: "baz", title: "two", cost: 45, color: "green" },
|
|
39
|
-
];
|
|
40
|
-
const fn = <T extends Record<string, Narrowable>, A extends readonly T[]>(arr: A): A => arr;
|
|
41
|
-
|
|
42
|
-
const v = fn(genericArr);
|
|
43
|
-
type V = typeof v;
|
|
44
|
-
type T1 = RequiredKeys<First<V>>;
|
|
45
|
-
type T2 = RequiredKeys<First<V>, string>;
|
|
46
|
-
|
|
47
|
-
type cases = [
|
|
48
|
-
Expect<Equal<T1, "id" | "name" | "title">>, //
|
|
49
|
-
Expect<Equal<T2, "name" | "title">>
|
|
50
|
-
];
|
|
51
|
-
const cases: cases = [true, true];
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import { Equal, Expect } from "@type-challenges/utils";
|
|
3
|
-
import { TypeDefault } from "src/types/boolean-logic/TypeDefault";
|
|
4
|
-
import { literal } from "src/runtime/literals";
|
|
5
|
-
|
|
6
|
-
describe("TypeDefault<T,D>", () => {
|
|
7
|
-
it("T/D as dictionary", () => {
|
|
8
|
-
type T = { foo?: "foo" | "fooy" | undefined; bar?: 42 | 53 | undefined };
|
|
9
|
-
type D = { foo: "foo"; bar: 42 };
|
|
10
|
-
type V = TypeDefault<T, D>;
|
|
11
|
-
const t1 = literal({ foo: undefined, bar: 56 });
|
|
12
|
-
type V1 = TypeDefault<typeof t1, D>;
|
|
13
|
-
const t2 = { foo: undefined, bar: 56 };
|
|
14
|
-
type V2 = TypeDefault<typeof t2, D>;
|
|
15
|
-
// const t3 = { bar: 56, baz: "hello" } as const;
|
|
16
|
-
// type _V3 = TypeDefault<typeof t3, D>;
|
|
17
|
-
|
|
18
|
-
type cases = [
|
|
19
|
-
// D's props all extend T
|
|
20
|
-
Expect<Equal<V, D>>,
|
|
21
|
-
// foo is inherited from default, bar keeps literal type from T
|
|
22
|
-
Expect<Equal<V1, { foo: "foo"; bar: 56 }>>,
|
|
23
|
-
// bar is widened to "number" because that's the resolution T had
|
|
24
|
-
Expect<Equal<V2, { foo: "foo"; bar: number }>>
|
|
25
|
-
// the T prop has the prop "baz" which did not exist on D
|
|
26
|
-
// TODO: this last test SHOULD work but doesn't yet
|
|
27
|
-
// Expect<Equal<V3, { foo: "foo"; bar: 56; baz: "hello" }>>
|
|
28
|
-
];
|
|
29
|
-
const cases: cases = [true, true, true];
|
|
30
|
-
});
|
|
31
|
-
it("T is undefined, D is a dictionary", () => {
|
|
32
|
-
type T = undefined;
|
|
33
|
-
type D = { foo: "foo"; bar: 42 };
|
|
34
|
-
type V = TypeDefault<T, D>;
|
|
35
|
-
|
|
36
|
-
type cases = [
|
|
37
|
-
// the value's type is converted to the default
|
|
38
|
-
Expect<Equal<V, D>>
|
|
39
|
-
];
|
|
40
|
-
const cases: cases = [true];
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("T and D are scalars", () => {
|
|
44
|
-
type T1 = 5;
|
|
45
|
-
type D1 = 8;
|
|
46
|
-
type V1 = TypeDefault<T1, D1>;
|
|
47
|
-
|
|
48
|
-
type T2 = "foo";
|
|
49
|
-
type D2 = "bar";
|
|
50
|
-
type V2 = TypeDefault<T2, D2>;
|
|
51
|
-
|
|
52
|
-
type T3 = undefined;
|
|
53
|
-
type D3 = "bar";
|
|
54
|
-
type V3 = TypeDefault<T3, D3>;
|
|
55
|
-
|
|
56
|
-
type cases = [
|
|
57
|
-
Expect<Equal<V1, 5>>, //
|
|
58
|
-
Expect<Equal<V2, "foo">>,
|
|
59
|
-
Expect<Equal<V3, "bar">>
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const cases: cases = [true, true, true];
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("Property includes a function", () => {
|
|
66
|
-
type T1 = { foo: "foo"; bar: undefined };
|
|
67
|
-
type D1 = { foo: "bar"; bar: () => "hello" };
|
|
68
|
-
type V1 = TypeDefault<T1, D1>;
|
|
69
|
-
|
|
70
|
-
type cases = [
|
|
71
|
-
Expect<Equal<V1["foo"], "foo">>, //
|
|
72
|
-
Expect<Equal<V1["bar"], () => "hello">>
|
|
73
|
-
];
|
|
74
|
-
const cases: cases = [true, true];
|
|
75
|
-
});
|
|
76
|
-
});
|