-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
👍 Add isObjectOf
modify functions (isReadonlyOf
, isStrictOf
, isRequiredOf
, isPartialOf
, isPickOf
, and isOmitOf
)
#57
Conversation
Previously, `isRecord` returned `true` for `Date` and `Promise` objects. This commit fixes it to return `true` only for plain objects.
Warning Rate Limit Exceeded@lambdalisue has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 2 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe recent updates streamline type checking capabilities, introduce new type utilities, and organize functionality across various files. These changes aim to enhance type narrowing and checking in TypeScript, facilitating work with intricate types and ensuring type safety. The updates encompass utilities for flat typing, union to intersection conversion, comprehensive type predicates, and metadata management for predicates. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #57 +/- ##
==========================================
- Coverage 99.61% 97.79% -1.82%
==========================================
Files 3 8 +5
Lines 513 635 +122
Branches 56 68 +12
==========================================
+ Hits 511 621 +110
- Misses 2 14 +12 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 22
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
is/__snapshots__/factory_test.ts.snap
is excluded by:!**/*.snap
is/__snapshots__/utility_test.ts.snap
is excluded by:!**/*.snap
Files selected for processing (11)
- _typeutil.ts (1 hunks)
- is.ts (1 hunks)
- is/_testutil.ts (1 hunks)
- is/core.ts (1 hunks)
- is/core_test.ts (1 hunks)
- is/factory.ts (1 hunks)
- is/factory_test.ts (20 hunks)
- is/type.ts (1 hunks)
- is/utility.ts (1 hunks)
- is/utility_test.ts (1 hunks)
- metadata.ts (1 hunks)
Additional comments: 11
_typeutil.ts (1)
- 1-8: LGTM!
is.ts (1)
- 1-13: LGTM!
is/_testutil.ts (1)
- 1-13: LGTM!
is/type.ts (1)
- 1-26: LGTM!
metadata.ts (1)
- 1-43: LGTM!
is/core_test.ts (1)
- 1-223: LGTM!
is/core.ts (1)
- 1-354: LGTM!
is/utility.ts (1)
- 1-334: LGTM!
is/utility_test.ts (3)
- 85-118: The test case for
isOneOf<T>
usesassertSnapshot
without verifying the snapshot's content. Ensure snapshots are meaningful and reviewed for correctness.Ensure the snapshot content for
isOneOf
function names is meaningful and correctly verifies the expected behavior.
- 121-166: Similar to the previous comment, verify the snapshot content for
isAllOf<T>
function names to ensure it aligns with expected behavior.Ensure the snapshot content for
isAllOf
function names is meaningful and correctly verifies the expected behavior.
- 169-245: For
isOptionalOf<T>
, ensure that the test cases cover all relevant scenarios, including passing undefined to non-optional predicates and ensuring the behavior aligns with expectations.Review the test cases for
isOptionalOf
to ensure comprehensive coverage, including edge cases and incorrect type handling.
is/factory_test.ts
Outdated
import { type Equal, stringify } from "./_testutil.ts"; | ||
import { type Predicate } from "./type.ts"; | ||
import { isArray, isBoolean, isNumber, isString } from "./core.ts"; | ||
import is, { | ||
isAllOf, | ||
isAny, | ||
isArray, | ||
isArrayOf, | ||
isAsyncFunction, | ||
isBigInt, | ||
isBoolean, | ||
isFunction, | ||
isInstanceOf, | ||
isLiteralOf, | ||
isLiteralOneOf, | ||
isMap, | ||
isMapOf, | ||
isNull, | ||
isNullish, | ||
isNumber, | ||
isObjectOf, | ||
isOneOf, | ||
isOptionalOf, | ||
isPrimitive, | ||
isReadonlyTupleOf, | ||
isReadonlyUniformTupleOf, | ||
isRecord, | ||
isRecordOf, | ||
isSet, | ||
isSetOf, | ||
isString, | ||
isSymbol, | ||
isSyncFunction, | ||
isTupleOf, | ||
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 | ||
// https://github.com/type-challenges/type-challenges/blob/e77262dba62e9254451f661cb4fe5517ffd1d933/utils/index.d.ts#L7-L9 | ||
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends | ||
(<T>() => T extends Y ? 1 : 2) ? true : false; | ||
} from "./factory.ts"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider grouping imports from the same module into a single import statement to improve readability and maintain consistency.
- import {
- assertEquals,
- assertStrictEquals,
- } from "https://deno.land/[email protected]/assert/mod.ts";
- import {
- assertSnapshot,
- } from "https://deno.land/[email protected]/testing/snapshot.ts";
- import { assertType } from "https://deno.land/[email protected]/testing/types.ts";
+ import {
+ assertEquals,
+ assertStrictEquals,
+ assertSnapshot,
+ assertType,
+ } from "https://deno.land/[email protected]/assert/mod.ts";
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import { type Equal, stringify } from "./_testutil.ts"; | |
import { type Predicate } from "./type.ts"; | |
import { isArray, isBoolean, isNumber, isString } from "./core.ts"; | |
import is, { | |
isAllOf, | |
isAny, | |
isArray, | |
isArrayOf, | |
isAsyncFunction, | |
isBigInt, | |
isBoolean, | |
isFunction, | |
isInstanceOf, | |
isLiteralOf, | |
isLiteralOneOf, | |
isMap, | |
isMapOf, | |
isNull, | |
isNullish, | |
isNumber, | |
isObjectOf, | |
isOneOf, | |
isOptionalOf, | |
isPrimitive, | |
isReadonlyTupleOf, | |
isReadonlyUniformTupleOf, | |
isRecord, | |
isRecordOf, | |
isSet, | |
isSetOf, | |
isString, | |
isSymbol, | |
isSyncFunction, | |
isTupleOf, | |
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 | |
// https://github.com/type-challenges/type-challenges/blob/e77262dba62e9254451f661cb4fe5517ffd1d933/utils/index.d.ts#L7-L9 | |
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends | |
(<T>() => T extends Y ? 1 : 2) ? true : false; | |
} from "./factory.ts"; | |
import { type Equal, stringify } from "./_testutil.ts"; | |
import { type Predicate } from "./type.ts"; | |
import { isArray, isBoolean, isNumber, isString } from "./core.ts"; | |
import is, { | |
isArrayOf, | |
isInstanceOf, | |
isLiteralOf, | |
isLiteralOneOf, | |
isMapOf, | |
isObjectOf, | |
isReadonlyTupleOf, | |
isReadonlyUniformTupleOf, | |
isRecordOf, | |
isSetOf, | |
isTupleOf, | |
isUniformTupleOf, | |
} from "./factory.ts"; | |
import { | |
assertEquals, | |
assertStrictEquals, | |
assertSnapshot, | |
assertType, | |
} from "https://deno.land/[email protected]/assert/mod.ts"; |
isTupleOf([isNumber, isString, isBoolean], isArray).name, | ||
); | ||
await assertSnapshot( | ||
t, | ||
isTupleOf([(_x): _x is string => false], is.ArrayOf(is.String)) | ||
isTupleOf([(_x): _x is string => false], isArrayOf(isString)) | ||
.name, | ||
); | ||
// Nested | ||
await assertSnapshot( | ||
t, | ||
isTupleOf([ | ||
isTupleOf( | ||
[isTupleOf([isNumber, isString, isBoolean], is.Array)], | ||
is.Array, | ||
[isTupleOf([isNumber, isString, isBoolean], isArray)], | ||
isArray, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case for isTupleOf<T, E>
uses a nested tuple predicate in a complex manner. Ensure that this complexity is necessary for adequately testing the functionality. If the complexity does not add value, consider simplifying the test case to focus on the primary behavior of isTupleOf<T, E>
.
Deno.test("is", async (t) => { | ||
const mod = await import("./is.ts"); | ||
const mod = await import("./factory.ts"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic import of ./factory.ts
within the test for the is
object might introduce unnecessary complexity and potential delays in test execution. If the functions from factory.ts
are static and known at compile time, consider directly importing them instead of using dynamic import.
is/factory.ts
Outdated
export function isArrayOf<T>( | ||
pred: Predicate<T>, | ||
): Predicate<T[]> & WithMetadata<IsArrayOfMetadata> { | ||
return setPredicateMetadata( | ||
(x: unknown): x is T[] => isArray(x) && x.every(pred), | ||
{ name: "isArrayOf", args: [pred] }, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling or validation for the pred
argument in isArrayOf
to ensure it's a valid predicate function before using it.
is/factory.ts
Outdated
export function isSetOf<T>( | ||
pred: Predicate<T>, | ||
): Predicate<Set<T>> & WithMetadata<IsSetOfMetadata> { | ||
return setPredicateMetadata( | ||
(x: unknown): x is Set<T> => { | ||
if (!isSet(x)) return false; | ||
for (const v of x.values()) { | ||
if (!pred(v)) return false; | ||
} | ||
return true; | ||
}, | ||
{ name: "isSetOf", args: [pred] }, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In isSetOf
, validate the pred
argument to ensure it's a function. This prevents potential runtime errors when invoking pred(v)
.
is/utility_test.ts
Outdated
c: isBoolean, | ||
}; | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a", c: "" }), | ||
false, | ||
"Object have a different type property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a" }), | ||
false, | ||
"Object does not have one property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ | ||
a: 0, | ||
b: "a", | ||
c: true, | ||
d: "invalid", | ||
}), | ||
false, | ||
"Object have an unknown property", | ||
); | ||
}); | ||
await testWithExamples( | ||
t, | ||
isStrictOf(isObjectOf({ a: (_: unknown): _ is unknown => false })), | ||
{ excludeExamples: ["record"] }, | ||
); | ||
await t.step("with optional properties", async (t) => { | ||
await t.step("returns proper type predicate", () => { | ||
const predObj = { | ||
a: isNumber, | ||
b: isOneOf([isString, isUndefined]), | ||
c: isOptionalOf(isBoolean), | ||
}; | ||
const a: unknown = { a: 0, b: "a" }; | ||
if (isStrictOf(isObjectOf(predObj))(a)) { | ||
assertType< | ||
Equal<typeof a, { a: number; b: string | undefined; c?: boolean }> | ||
>(true); | ||
} | ||
}); | ||
await t.step("returns true on T object", () => { | ||
const predObj = { | ||
a: isNumber, | ||
b: isOneOf([isString, isUndefined]), | ||
c: isOptionalOf(isBoolean), | ||
}; | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a", c: true }), | ||
true, | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a" }), | ||
true, | ||
"Object does not have an optional property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a", c: undefined }), | ||
true, | ||
"Object has `undefined` as value of optional property", | ||
); | ||
}); | ||
await t.step("returns false on non T object", () => { | ||
const predObj = { | ||
a: isNumber, | ||
b: isOneOf([isString, isUndefined]), | ||
c: isOptionalOf(isBoolean), | ||
}; | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a", c: "" }), | ||
false, | ||
"Object have a different type property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ a: 0, b: "a", c: null }), | ||
false, | ||
"Object has `null` as value of optional property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ | ||
a: 0, | ||
b: "a", | ||
c: true, | ||
d: "invalid", | ||
}), | ||
false, | ||
"Object have an unknown property", | ||
); | ||
assertEquals( | ||
isStrictOf(isObjectOf(predObj))({ | ||
a: 0, | ||
b: "a", | ||
d: "invalid", | ||
}), | ||
false, | ||
"Object have the same number of properties but an unknown property exists", | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the isStrictOf<T>
test cases, consider adding tests that verify the behavior when optional properties are provided with incorrect types, to ensure the predicate correctly identifies type mismatches.
Add test cases for isStrictOf
that cover scenarios where optional properties are provided but with incorrect types.
is/utility_test.ts
Outdated
Deno.test("isPartialOf<T>", async (t) => { | ||
const pred = isObjectOf({ | ||
a: isNumber, | ||
b: isString, | ||
c: isBoolean, | ||
}); | ||
await t.step("returns properly named function", async (t) => { | ||
await assertSnapshot(t, isPartialOf(pred).name); | ||
// Nestable (no effect) | ||
await assertSnapshot(t, isPartialOf(isPartialOf(pred)).name); | ||
}); | ||
await t.step("returns proper type predicate", () => { | ||
const a: unknown = { a: 0, b: "a", c: true }; | ||
if (isPartialOf(pred)(a)) { | ||
assertType< | ||
Equal<typeof a, Partial<{ a: number; b: string; c: boolean }>> | ||
>(true); | ||
} | ||
}); | ||
await t.step("returns true on Partial<T> object", () => { | ||
assertEquals( | ||
isPartialOf(pred)({ a: undefined, b: undefined, c: undefined }), | ||
true, | ||
); | ||
assertEquals(isPartialOf(pred)({}), true); | ||
}); | ||
await t.step("returns false on non Partial<T> object", () => { | ||
assertEquals(isPartialOf(pred)("a"), false, "Value is not an object"); | ||
assertEquals( | ||
isPartialOf(pred)({ a: 0, b: "a", c: "" }), | ||
false, | ||
"Object have a different type property", | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For isPartialOf<T>
, ensure that the test cases adequately cover scenarios where partial objects with incorrect types for the defined properties are passed, to validate the predicate's robustness.
Add test cases for isPartialOf
that cover scenarios with partial objects having incorrect types for their defined properties.
Deno.test("isPickOf<T, K>", async (t) => { | ||
const pred = isObjectOf({ | ||
a: isNumber, | ||
b: isString, | ||
c: isBoolean, | ||
}); | ||
await t.step("returns properly named function", async (t) => { | ||
await assertSnapshot(t, isPickOf(pred, ["a", "c"]).name); | ||
// Nestable | ||
await assertSnapshot(t, isPickOf(isPickOf(pred, ["a", "c"]), ["a"]).name); | ||
}); | ||
await t.step("returns proper type predicate", () => { | ||
const a: unknown = { a: 0, b: "a", c: true }; | ||
if (isPickOf(pred, ["a", "c"])(a)) { | ||
assertType< | ||
Equal<typeof a, { a: number; c: boolean }> | ||
>(true); | ||
} | ||
if (isPickOf(isPickOf(pred, ["a", "c"]), ["a"])(a)) { | ||
assertType< | ||
Equal<typeof a, { a: number }> | ||
>(true); | ||
} | ||
}); | ||
await t.step("returns true on Pick<T, K> object", () => { | ||
assertEquals( | ||
isPickOf(pred, ["a", "c"])({ a: 0, b: undefined, c: true }), | ||
true, | ||
); | ||
assertEquals(isPickOf(pred, ["a"])({ a: 0 }), true); | ||
}); | ||
await t.step("returns false on non Pick<T, K> object", () => { | ||
assertEquals( | ||
isPickOf(pred, ["a", "c"])("a"), | ||
false, | ||
"Value is not an object", | ||
); | ||
assertEquals( | ||
isPickOf(pred, ["a", "c"])({ a: 0, b: "a", c: "" }), | ||
false, | ||
"Object have a different type property", | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the isPickOf<T, K>
test cases, consider verifying the behavior when picked properties are of incorrect types, to ensure the predicate accurately identifies type mismatches.
Add test cases for isPickOf
that cover scenarios where picked properties are of incorrect types.
Deno.test("isOmitOf<T, K>", async (t) => { | ||
const pred = isObjectOf({ | ||
a: isNumber, | ||
b: isString, | ||
c: isBoolean, | ||
}); | ||
await t.step("returns properly named function", async (t) => { | ||
await assertSnapshot(t, isOmitOf(pred, ["b"]).name); | ||
// Nestable | ||
await assertSnapshot(t, isOmitOf(isOmitOf(pred, ["b"]), ["c"]).name); | ||
}); | ||
await t.step("returns proper type predicate", () => { | ||
const a: unknown = { a: 0, b: "a", c: true }; | ||
if (isOmitOf(pred, ["b"])(a)) { | ||
assertType< | ||
Equal<typeof a, { a: number; c: boolean }> | ||
>(true); | ||
} | ||
if (isOmitOf(isOmitOf(pred, ["b"]), ["c"])(a)) { | ||
assertType< | ||
Equal<typeof a, { a: number }> | ||
>(true); | ||
} | ||
}); | ||
await t.step("returns true on Omit<T, K> object", () => { | ||
assertEquals( | ||
isOmitOf(pred, ["b"])({ a: 0, b: undefined, c: true }), | ||
true, | ||
); | ||
assertEquals(isOmitOf(pred, ["b", "c"])({ a: 0 }), true); | ||
}); | ||
await t.step("returns false on non Omit<T, K> object", () => { | ||
assertEquals( | ||
isOmitOf(pred, ["b"])("a"), | ||
false, | ||
"Value is not an object", | ||
); | ||
assertEquals( | ||
isOmitOf(pred, ["b"])({ a: 0, b: "a", c: "" }), | ||
false, | ||
"Object have a different type property", | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For isOmitOf<T, K>
, ensure that the test cases cover scenarios where omitted properties are incorrectly included in the object, to validate the predicate's ability to detect unexpected properties.
Add test cases for isOmitOf
that cover scenarios where omitted properties are incorrectly included in the object.
Deno.test("is", async (t) => { | ||
const mod = await import("./utility.ts"); | ||
const casesOfAliasAndIsFunction = Object.entries(mod) | ||
.filter(([k, _]) => k.startsWith("is")) | ||
.map(([k, v]) => [k.slice(2), v] as const); | ||
for (const [alias, fn] of casesOfAliasAndIsFunction) { | ||
await t.step(`defines \`${alias}\` function`, () => { | ||
assertStrictEquals(is[alias as keyof typeof is], fn); | ||
}); | ||
} | ||
await t.step( | ||
"only has entries that are the same as the `is*` function aliases", | ||
() => { | ||
const aliases = casesOfAliasAndIsFunction.map(([a]) => a).sort(); | ||
assertEquals(Object.keys(is).sort(), aliases); | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case for verifying is
aliases does not check for potential duplicates or missing entries in the is
object. Consider adding checks to ensure all expected predicates are present and correctly aliased.
Add checks to ensure there are no duplicates or missing entries in the is
object, verifying all expected predicates are present and correctly aliased.
f1f22c8
to
f4df8e9
Compare
Predicates functions other than `isObjectOf` do not make sense with `isAllOf`. Therefore, the implementation of `isAllOf` has been simplified to internally utilize `isObjectOf`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
is/__snapshots__/factory_test.ts.snap
is excluded by:!**/*.snap
is/__snapshots__/utility_test.ts.snap
is excluded by:!**/*.snap
Files selected for processing (12)
- _typeutil.ts (1 hunks)
- is.ts (1 hunks)
- is/_testutil.ts (1 hunks)
- is/core.ts (1 hunks)
- is/core_test.ts (1 hunks)
- is/factory.ts (1 hunks)
- is/factory_test.ts (23 hunks)
- is/type.ts (1 hunks)
- is/utility.ts (1 hunks)
- is/utility_test.ts (1 hunks)
- is_bench.ts (1 hunks)
- metadata.ts (1 hunks)
Files skipped from review as they are similar to previous changes (10)
- _typeutil.ts
- is.ts
- is/_testutil.ts
- is/core.ts
- is/core_test.ts
- is/factory.ts
- is/type.ts
- is/utility.ts
- is/utility_test.ts
- metadata.ts
Additional comments: 3
is_bench.ts (1)
- 516-519: The addition of
is.ObjectOf({ a: is.Number })
andis.ObjectOf({ b: is.String })
to thepredsAll
array introduces more specific object type checks. Ensure these new predicates are correctly implemented and align with the PR's objectives to enhance type checking capabilities. The use ofas const
ensures type correctness for the tuple, which is good practice.is/factory_test.ts (2)
- 186-199: The complexity of the nested
isTupleOf
test case has been previously flagged. Ensure the complexity is justified by the test's objectives. If not, simplify to focus on primary behavior.- 957-957: The dynamic import within the test for the
is
object has been previously flagged. Consider directly importing./factory.ts
to avoid unnecessary complexity and potential delays.
77d9bc7
to
2ceadda
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
is/__snapshots__/factory_test.ts.snap
is excluded by:!**/*.snap
is/__snapshots__/utility_test.ts.snap
is excluded by:!**/*.snap
Files selected for processing (6)
- README.md (3 hunks)
- is/factory.ts (1 hunks)
- is/utility.ts (1 hunks)
- is/utility_test.ts (1 hunks)
- metadata.ts (1 hunks)
- mod.ts (3 hunks)
Files skipped from review as they are similar to previous changes (4)
- is/factory.ts
- is/utility.ts
- is/utility_test.ts
- metadata.ts
Additional comments: 6
mod.ts (3)
- 33-51: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [24-45]
Ensure the examples provided are accurate and align with the TypeScript syntax and library's API. The usage of
is.OptionalOf
is correctly demonstrated for optional properties.
- 71-139: The examples demonstrating
isPickOf
,isOmitOf
, andisPartialOf
are clear and effectively illustrate how these utilities can be used to manipulate predicate functions. This aligns well with TypeScript's utility types and enhances the library's functionality.- 68-164: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [141-169]
The examples for
isUnionOf
andisIntersectionOf
are correctly implemented and demonstrate the library's capability to handle union and intersection types. This addition significantly enhances the library's type manipulation capabilities.README.md (3)
- 43-61: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [34-55]
The documentation correctly introduces the new
is*Of
functions and provides an example that aligns with the changes inmod.ts
. This ensures users understand how to use these new functionalities.
- 81-148: The explanation and examples for manipulating predicate functions with
isPickOf
,isOmitOf
, andisPartialOf
are accurately documented. This section effectively communicates how these utilities work, mirroring the enhancements in the library.- 151-169: The documentation for
isUnionOf
andisIntersectionOf
is clear and provides examples that correctly demonstrate their usage. This addition to the README ensures users are aware of these new type manipulation capabilities.
isObjectOf
modify functions (isReadonlyOf
, isStrictOf
, isPartialOf
, isPickOf
, and isOmitOf
)
d4e3285
to
40f5c8a
Compare
Eliminated redundant assignment of optional attributes since metadata is stored in the Predicate factory function. However, isObjectOf and type functions are checked for optional attributes to ensure backward compatibility.
40f5c8a
to
5d15f38
Compare
isObjectOf
modify functions (isReadonlyOf
, isStrictOf
, isPartialOf
, isPickOf
, and isOmitOf
)isObjectOf
modify functions (isReadonlyOf
, isStrictOf
, isRequiredOf
, isPartialOf
, isPickOf
, and isOmitOf
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (3)
is/__snapshots__/annotation_test.ts.snap
is excluded by:!**/*.snap
is/__snapshots__/factory_test.ts.snap
is excluded by:!**/*.snap
is/__snapshots__/utility_test.ts.snap
is excluded by:!**/*.snap
Files selected for processing (11)
- README.md (3 hunks)
- _typeutil.ts (1 hunks)
- is.ts (1 hunks)
- is/annotation.ts (1 hunks)
- is/annotation_test.ts (1 hunks)
- is/factory.ts (1 hunks)
- is/factory_test.ts (21 hunks)
- is/utility.ts (1 hunks)
- is/utility_test.ts (1 hunks)
- metadata.ts (1 hunks)
- mod.ts (4 hunks)
Files skipped from review as they are similar to previous changes (10)
- README.md
- _typeutil.ts
- is.ts
- is/annotation.ts
- is/annotation_test.ts
- is/factory.ts
- is/utility.ts
- is/utility_test.ts
- metadata.ts
- mod.ts
Additional comments: 3
is/factory_test.ts (3)
- 9-28: Imports from local modules (
_testutil.ts
,type.ts
,annotation.ts
,core.ts
,factory.ts
,utility.ts
) are correctly structured. Ensure all newly imported modules are utilized within the file to avoid unnecessary imports.- 172-185: The complexity of the nested
isTupleOf
test case has been previously flagged. Given the changes, ensure the complexity is justified by the test's intent to cover nested tuple validation scenarios comprehensively.- 864-864: The dynamic import within the test for the
is
object has been previously flagged. Re-evaluate if the dynamic import is necessary or if a static import could be used to simplify the test setup and potentially improve test execution time.
The following predicate factory functions are added/modified
isObjectOf
isStrictOf
isPartialOf
isRequiredOf
isPickOf
isOmitOf
isUnionOf
(renamed fromisOneOf
)isIntersectionOf
(renamed fromisAllOf
)isOptionalOf
isReadonlyOf
isUnwrapOptionalOf
isUnwrapReadonlyOf
Summary by CodeRabbit
New Features
is*Of
functions for precise validation.isUnionOf
,isIntersectionOf
,isPartialOf
,isPickOf
, andisOmitOf
.Refactor
Tests