From 34d2a04b06604b4cd017390d8aa11a5a1b6ae533 Mon Sep 17 00:00:00 2001 From: Alisue Date: Mon, 12 Feb 2024 19:52:05 +0900 Subject: [PATCH] :boom: Remove some internal types from the public --- is.ts | 84 ++++++++---------------------------------------------- is_test.ts | 53 ---------------------------------- 2 files changed, 12 insertions(+), 125 deletions(-) diff --git a/is.ts b/is.ts index d939f78..2722017 100644 --- a/is.ts +++ b/is.ts @@ -233,33 +233,11 @@ export function isSetOf( ); } -/** - * Tuple type of types that are predicated by an array of predicate functions. - * - * ```ts - * import { is, TupleOf } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts"; - * - * type A = TupleOf; - * // Above is equivalent to the following type - * // type A = [string, number]; - * ``` - */ -export type TupleOf = { +type TupleOf = { -readonly [P in keyof T]: T[P] extends Predicate ? U : never; }; -/** - * Readonly tuple type of types that are predicated by an array of predicate functions. - * - * ```ts - * import { is, ReadonlyTupleOf } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts"; - * - * type A = ReadonlyTupleOf; - * // Above is equivalent to the following type - * // type A = readonly [string, number]; - * ``` - */ -export type ReadonlyTupleOf = { +type ReadonlyTupleOf = { [P in keyof T]: T[P] extends Predicate ? U : never; }; @@ -454,36 +432,14 @@ export function isReadonlyTupleOf< } } -/** - * Uniform tuple type of types that are predicated by a predicate function and the length is `N`. - * - * ```ts - * import { is, UniformTupleOf } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts"; - * - * type A = UniformTupleOf; - * // Above is equivalent to the following type - * // type A = [number, number, number, number, number]; - * ``` - */ // https://stackoverflow.com/a/71700658/1273406 -export type UniformTupleOf< +type UniformTupleOf< T, N extends number, R extends readonly T[] = [], > = R["length"] extends N ? R : UniformTupleOf; -/** - * Readonly uniform tuple type of types that are predicated by a predicate function `T` and the length is `N`. - * - * ```ts - * import { is, ReadonlyUniformTupleOf } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts"; - * - * type A = ReadonlyUniformTupleOf; - * // Above is equivalent to the following type - * // type A = readonly [number, number, number, number, number]; - * ``` - */ -export type ReadonlyUniformTupleOf< +type ReadonlyUniformTupleOf< T, N extends number, R extends readonly T[] = [], @@ -581,11 +537,6 @@ export function isReadonlyUniformTupleOf( ); } -/** - * Synonym of `Record` - */ -export type RecordOf = Record; - /** * Return `true` if the type of `x` is `Record`. * @@ -732,22 +683,11 @@ export function isMapOf( ); } -type OptionalPredicateKeys> = { +type OptionalPredicateKeys> = { [K in keyof T]: T[K] extends OptionalPredicate ? K : never; }[keyof T]; -/** - * Object types that are predicated by predicate functions in the object `T`. - * - * ```ts - * import { is, ObjectOf } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts"; - * - * type A = ObjectOf<{ a: typeof is.Number, b: typeof is.String }>; - * // Above is equivalent to the following type - * // type A = { a: number; b: string }; - * ``` - */ -export type ObjectOf>> = FlatType< +type ObjectOf>> = FlatType< & { [K in Exclude>]: T[K] extends Predicate ? U : never; @@ -801,7 +741,7 @@ export type ObjectOf>> = FlatType< * ``` */ export function isObjectOf< - T extends RecordOf>, + T extends Record>, >( predObj: T, { strict }: { strict?: boolean } = {}, @@ -817,7 +757,7 @@ export function isObjectOf< } function isObjectOfLoose< - T extends RecordOf>, + T extends Record>, >( predObj: T, ): Predicate> { @@ -831,7 +771,7 @@ function isObjectOfLoose< } function isObjectOfStrict< - T extends RecordOf>, + T extends Record>, >( predObj: T, ): Predicate> { @@ -1081,7 +1021,7 @@ export function isLiteralOneOf( ); } -export type OneOf = T extends readonly [Predicate, ...infer R] +type OneOf = T extends readonly [Predicate, ...infer R] ? U | OneOf : never; @@ -1131,7 +1071,7 @@ export function isOneOf< ); } -export type AllOf = UnionToIntersection>; +type AllOf = UnionToIntersection>; /** * Return a type predicate function that returns `true` if the type of `x` is `AllOf`. @@ -1185,7 +1125,7 @@ export function isAllOf< ); } -export type OptionalPredicate = Predicate & { +type OptionalPredicate = Predicate & { optional: true; }; diff --git a/is_test.ts b/is_test.ts index d6d2244..287075b 100644 --- a/is_test.ts +++ b/is_test.ts @@ -40,13 +40,8 @@ import is, { isUndefined, isUniformTupleOf, isUnknown, - ObjectOf, Predicate, PredicateType, - ReadonlyTupleOf, - ReadonlyUniformTupleOf, - TupleOf, - UniformTupleOf, } from "./is.ts"; // It seems 'IsExact' in deno_std is false positive so use `Equal` in type-challenges @@ -252,24 +247,6 @@ Deno.test("isSetOf", async (t) => { }); }); -Deno.test("TupleOf", () => { - assertType< - Equal< - TupleOf, - [string, number] - > - >(true); -}); - -Deno.test("ReadonlyTupleOf", () => { - assertType< - Equal< - ReadonlyTupleOf, - readonly [string, number] - > - >(true); -}); - Deno.test("isTupleOf", async (t) => { await t.step("returns properly named function", async (t) => { await assertSnapshot( @@ -482,27 +459,6 @@ Deno.test("isReadonlyTupleOf", async (t) => { ); }); -Deno.test("UniformTupleOf", () => { - assertType< - Equal, [number, number, number, number, number]> - >(true); -}); - -Deno.test("ReadonlyUniformTupleOf", () => { - assertType< - Equal< - ReadonlyUniformTupleOf, - readonly [ - number, - number, - number, - number, - number, - ] - > - >(true); -}); - Deno.test("isUniformTupleOf", async (t) => { await t.step("returns properly named function", async (t) => { await assertSnapshot(t, isUniformTupleOf(3).name); @@ -715,15 +671,6 @@ Deno.test("isMapOf", async (t) => { }); }); -Deno.test("ObjectOf", () => { - assertType< - Equal< - ObjectOf<{ a: typeof is.Number; b: typeof is.String }>, - { a: number; b: string } - > - >(true); -}); - Deno.test("isObjectOf", async (t) => { await t.step("returns properly named function", async (t) => { await assertSnapshot(