Skip to content
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

Merged
merged 31 commits into from
Feb 12, 2024

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Feb 12, 2024

The following predicate factory functions are added/modified

  • isObjectOf
  • isStrictOf
  • isPartialOf
  • isRequiredOf
  • isPickOf
  • isOmitOf
  • isUnionOf (renamed from isOneOf)
  • isIntersectionOf (renamed from isAllOf)
  • isOptionalOf
  • isReadonlyOf
  • isUnwrapOptionalOf
  • isUnwrapReadonlyOf

Summary by CodeRabbit

  • New Features

    • Enhanced type checking with is*Of functions for precise validation.
    • Introduced advanced type manipulation utilities like isUnionOf, isIntersectionOf, isPartialOf, isPickOf, and isOmitOf.
    • Implemented metadata management for predicates to enrich type information.
  • Refactor

    • Restructured codebase for improved organization and clarity.
  • Tests

    • Expanded test coverage for type-checking functions to ensure robustness.

Copy link

coderabbitai bot commented Feb 12, 2024

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 5d15f38 and a3b2679.

Walkthrough

The 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

File(s) Change Summary
is/_testutil.ts Introduced stringify(x: unknown): string function and Equal<X, Y> type for type equality comparison.
is/core.ts, is/core_test.ts Introduced type-checking functions and their corresponding tests.
is/annotation.ts Introduced functions and types for annotating type predicate functions as Optional or Readonly.
is/factory.ts, is/factory_test.ts Introduced functions for creating type predicate functions and restructured related tests.
is/type.ts Introduced functionality for defining type predicate functions and deriving types.
is/utility.ts, is/utility_test.ts Introduced utility functions for creating type predicate functions and relevant test cases.
metadata.ts Introduced functionality for managing metadata associated with predicates.

"In a land of types and tales,
A rabbit hopped, leaving trails.
🐾 With each leap, a change it brought,
Types refined, and errors caught.
📚 From FlatType to Union blend,
It's a TypeScript tale, from start to end."
🎉🐇

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (f38987f) 99.61% compared to head (a3b2679) 97.79%.

Files Patch % Lines
is/utility.ts 88.37% 10 Missing ⚠️
is/annotation.ts 96.96% 2 Missing ⚠️
metadata.ts 97.22% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between f38987f and f1f22c8.
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> uses assertSnapshot 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.

Comment on lines 9 to 25
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";
Copy link

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.

Suggested change
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";

Comment on lines +169 to +182
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,
Copy link

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");
Copy link

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
Comment on lines 29 to 36
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] },
);
}
Copy link

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
Comment on lines 59 to 72
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] },
);
}
Copy link

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).

Comment on lines 248 to 395
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",
);
});
});
Copy link

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.

Comment on lines 398 to 431
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",
);
});
Copy link

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.

Comment on lines +434 to +476
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",
);
});
Copy link

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.

Comment on lines +479 to +521
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",
);
});
Copy link

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.

Comment on lines +524 to +540
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);
},
);
Copy link

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.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between f38987f and 317618a.
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 }) and is.ObjectOf({ b: is.String }) to the predsAll 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 of as 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.

@lambdalisue lambdalisue force-pushed the impl-objmodify branch 3 times, most recently from 77d9bc7 to 2ceadda Compare February 12, 2024 14:10
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 317618a and b39371d.
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, and isPartialOf 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 and isIntersectionOf 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 in mod.ts. This ensures users understand how to use these new functionalities.

  • 81-148: The explanation and examples for manipulating predicate functions with isPickOf, isOmitOf, and isPartialOf are accurately documented. This section effectively communicates how these utilities work, mirroring the enhancements in the library.
  • 151-169: The documentation for isUnionOf and isIntersectionOf 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.

@lambdalisue lambdalisue changed the title 👍 Add isObjectOf modify functions (isStrictOf, isPartialOf, isPickOf, and isOmitOf) 👍 Add isObjectOf modify functions (isReadonlyOf, isStrictOf, isPartialOf, isPickOf, and isOmitOf) Feb 12, 2024
@lambdalisue lambdalisue changed the title 👍 Add isObjectOf modify functions (isReadonlyOf, isStrictOf, isPartialOf, isPickOf, and isOmitOf) 👍 Add isObjectOf modify functions (isReadonlyOf, isStrictOf, isRequiredOf, isPartialOf, isPickOf, and isOmitOf) Feb 12, 2024
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 317618a and 5d15f38.
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.

@lambdalisue lambdalisue merged commit 5b4795c into main Feb 12, 2024
4 of 6 checks passed
@lambdalisue lambdalisue deleted the impl-objmodify branch February 12, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant