-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: use StringMap type for better type safety in utility functions #3220
Conversation
🦋 Changeset detectedLatest commit: af990ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@Gaic4o is attempting to deploy a commit to the NextUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe update focuses on enhancing type safety and flexibility within the codebase by replacing the usage of Changes
Possibly related PRs
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- .changeset/late-buttons-fail.md (1 hunks)
- packages/core/theme/src/utils/object.ts (2 hunks)
Additional comments not posted (4)
.changeset/late-buttons-fail.md (1)
1-5
: Changeset description accurately reflects the PR changes.packages/core/theme/src/utils/object.ts (3)
3-3
: Type aliasUnknownMap
defined correctly for enhanced type safety.
52-52
: TheflattenThemeObject
function uses theflatten
library correctly and ensures type safety by casting the result toUnknownMap
. Good use of generics and type casting.
5-26
: TheswapColorValues
function correctly implements the swapping logic using theUnknownMap
type. Ensure that all calls to this function are updated to handle the new type.Verification successful
The calls to
swapColorValues
inpackages/core/theme/src/colors/semantic.ts
appear to be passing arguments likecommon.zinc
,common.blue
, etc. To ensure these arguments match the newUnknownMap
type, we need to verify the type ofcommon.zinc
and similar variables.
The
commonColors
object is defined inpackages/core/theme/src/colors/common.ts
and includes properties likezinc
,blue
, etc. To ensure these properties match theUnknownMap
type, we need to verify the types ofzinc
,blue
, and other similar properties.
The properties
zinc
andblue
incommonColors
are defined as objects with string keys and color values, which align with theUnknownMap
type expected byswapColorValues
.
zinc
is defined inpackages/core/theme/src/colors/zinc.ts
as an object with string keys and color values.blue
is defined inpackages/core/theme/src/colors/blue.ts
similarly.Therefore, the calls to
swapColorValues
insemantic.ts
are correctly passing arguments that match theUnknownMap
type.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `swapColorValues` match the new signature. # Test: Search for the function usage. Expect: Only occurances of the new signature. rg --type typescript $'swapColorValues'Length of output: 73
Script:
#!/bin/bash # Description: Verify all function calls to `swapColorValues` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg 'swapColorValues' --glob '*.ts'Length of output: 799
Script:
#!/bin/bash # Description: Verify the context of calls to `swapColorValues` in `semantic.ts` to ensure they handle the new `UnknownMap` type. # Extract relevant lines around each call to `swapColorValues`. rg 'swapColorValues' --glob 'packages/core/theme/src/colors/semantic.ts' -A 3 -B 3Length of output: 3208
Script:
#!/bin/bash # Description: Verify the type of variables like `common.zinc` used in calls to `swapColorValues`. # Search for the definition of `common` in `common.ts`. rg 'commonColors as common' --glob 'packages/core/theme/src/colors/common.ts' -A 3 -B 3Length of output: 87
Script:
#!/bin/bash # Description: Verify the type of variables like `common.zinc` used in calls to `swapColorValues`. # Search for the definition of `commonColors` in `common.ts`. rg 'commonColors' --glob 'packages/core/theme/src/colors/common.ts' -A 3 -B 3Length of output: 726
Script:
#!/bin/bash # Description: Verify the types of properties like `zinc` and `blue` in `commonColors`. # Search for the definitions of `zinc` and `blue` in their respective files. rg 'export' --glob 'packages/core/theme/src/colors/zinc.ts' -A 3 -B 3 rg 'export' --glob 'packages/core/theme/src/colors/blue.ts' -A 3 -B 3Length of output: 603
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.
Any reason to use unknown
while the type for the value is known?
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.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- .changeset/late-buttons-fail.md (1 hunks)
- packages/core/theme/src/utils/object.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- .changeset/late-buttons-fail.md
- packages/core/theme/src/utils/object.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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
packages/core/theme/src/utils/object.ts (1)
6-7
: Function signature and internal typing are correctly updated.The updates to
swapColorValues
function are consistent with the PR's objectives. Consider adding a comment explaining the swapping logic for better maintainability.
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- packages/core/theme/src/utils/object.ts (2 hunks)
Additional comments not posted (2)
packages/core/theme/src/utils/object.ts (2)
3-4
: Type definitions are appropriate for the intended enhancements.The
ColorValue
andColorMap
types are well-defined and align with the PR's goal to enhance type safety.
53-53
: Proper use of type casting inflattenThemeObject
.The explicit casting to
ColorMap
is appropriate and ensures type safety.
@wingkwong Hello, I've modified the types based on the feedback you provided earlier. The pull request is still open, so please review it when you have a chance. If further changes aren't needed, I'll plan to close it. thank you |
Closing - let's keep it as it is first. |
📝 Description
Refactored utility functions to use
UnknownMap
type (Record<string, unknown>
) for better type safety and flexibility.⛳️ Current behavior (updates)
Record<string, string>
orObject
, causing potential type issues and limited flexibility.@ts-ignore
to bypass type checking.🚀 New behavior
UnknownMap
type for better type safety and flexibility.@ts-ignore
comments by addressing type issues directly.💣 Is this a breaking change (Yes/No):
No
Summary by CodeRabbit