Refactor validators to reduce repeated conditionals#8032
Merged
Conversation
Contributor
|
Netlify Draft Deployment |
Contributor
Hydration Benchmark Report (vs Baseline)✅ Top 5 Improvements (Best Speedups)
🔻 Flop 5 Regressions (Worst Slowdowns)
📋 Show all results
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors common object checks into a single isObject type guard and applies it across multiple prop validators to eliminate repeated inline conditionals.
- Updated
isObjectto be a type guard for better narrowing. - Replaced
typeof value === 'object' && value !== nullwithisObjectin various prop validators. - Streamlined multiple
watchValidatorand array validations.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/components/src/schema/validators/common.ts | Changed isObject return type to a type guard |
| packages/components/src/schema/props/toolbar-items.ts | Replaced inline object check with isObject |
| packages/components/src/schema/props/table-data.ts | Replaced inline object check with isObject |
| packages/components/src/schema/props/table-data-foot.ts | Replaced inline object check with isObject |
| packages/components/src/schema/props/table-callbacks.ts | Inlined watchValidator call to use isObject |
| packages/components/src/schema/props/popover-callbacks.ts | Swapped inline object check for isObject |
| packages/components/src/schema/props/options.ts | Swapped inline object check for isObject |
| packages/components/src/schema/props/icons.ts | Added KoliBriAllIcons type and swapped object checks |
| packages/components/src/schema/props/details-callbacks.ts | Swapped inline object check for isObject |
| packages/components/src/schema/props/button-callbacks.ts | Swapped inline object check for isObject |
| packages/components/src/schema/props/accordion-callbacks.ts | Swapped inline object check for isObject |
Comments suppressed due to low confidence (2)
packages/components/src/schema/validators/common.ts:1
- Consider adding unit tests for the
isObjecttype guard to verify correct narrowing behavior for various inputs (e.g., arrays, functions, primitives,null).
export const isObject = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null;
packages/components/src/schema/props/icons.ts:28
- The code uses
isObject(and laterisString) but neither is imported in this file. Please addimport { isObject, isString } from '../validators';to avoid runtime errors.
if (isObject(icon)) {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors validation logic across multiple files by introducing a more robust
isObjectutility function and replacing repetitive object validation code with calls to this function. Additionally, it introduces type refinements for better type safety and consistency.Refactoring Object Validation Logic:
Introduction of a refined
isObjectutility function: Updated theisObjectfunction to include type refinement, ensuring it checks whether a value is a non-null object and explicitly defines it asRecord<string, unknown>for type safety. (packages/components/src/schema/validators/common.ts)Replacement of manual object validation with
isObject: Replaced repetitive object validation logic (e.g.,typeof value === 'object' && value !== null) with calls to theisObjectutility function across multiple files, including:accordion-callbacks.tsbutton-callbacks.tsdetails-callbacks.tspopover-callbacks.tstable-callbacks.tsicons.ts[1] [2]options.tstable-data.tstable-data-foot.tstoolbar-items.tsType Refinements and Code Consistency:
icons.ts: IntroducedKoliBriAllIconstype and updated logic to use this refined type for better clarity and type checking when handling icon properties. (packages/components/src/schema/props/icons.ts)isObject, reducing redundancy and improving readability across all affected files.