-
Notifications
You must be signed in to change notification settings - Fork 531
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: remove index signature from base request #2923
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request enhances error handling in the Changes
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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: 0
🧹 Nitpick comments (1)
packages/xrpl/src/client/index.ts (1)
346-346
: Good defensive programming improvement.This change improves code safety by first checking if the
account
property exists in the request object before checking its type. This pattern prevents potential TypeErrors when the property doesn't exist, especially important after removing the index signature from theBaseRequest
interface (as mentioned in the PR objectives).The code now properly handles the case where a request doesn't include an
account
property, ensuring more robust error handling.According to the ESLint configuration, you should use single quotes instead of double quotes:
- "account" in req && typeof req.account === 'string' + 'account' in req && typeof req.account === 'string'🧰 Tools
🪛 ESLint
[error] 346-346: Replace
"account"
with'account'
(prettier/prettier)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/xrpl/src/client/index.ts
(1 hunks)packages/xrpl/src/models/methods/baseMethod.ts
(0 hunks)
💤 Files with no reviewable changes (1)
- packages/xrpl/src/models/methods/baseMethod.ts
🧰 Additional context used
🪛 ESLint
packages/xrpl/src/client/index.ts
[error] 346-346: Replace "account"
with 'account'
(prettier/prettier)
High Level Overview of Change
[key: string]: any
) from the baserequest
method's TypeScript interface in the XRPL.js library.Omit<>
andPartial<>
, making it easier for third-party developers to extend or manipulate therequest
type in their own projects.Context of Change
request
method likely used an index signature to allow arbitrary key-value pairs, which provided flexibility but sacrificed type safety and discoverability. For example, a definition likeinterface Request { [key: string]: any }
would allow any string key with any value, making it harder for developers to catch errors at compile time and limiting the utility of TypeScript’s tooling (e.g., autocompletion, refactoring).method: string
,params?: object
). This aligns with TypeScript best practices, as index signatures should only be used when the keys are truly dynamic and unknown ahead of time.Omit<Request, 'params'>
orPartial<Request>
) to customize therequest
type without running into issues caused by the loose index signature.[key: string]: string | number
), but removing it entirely was chosen to enforce stricter typing and better align with the library’s intended usage patterns.Type of Change
(Prevents potential type misuse, though not tied to a specific runtime bug.)
(Assumed non-breaking since existing valid usage should still work with explicit types.)
(Primary intent is to improve type structure, making this a refactor as well.)
Did you update HISTORY.md?
(The change is internal to the type system and transparent to end users interacting with the library’s runtime behavior. It mainly benefits developers working with the typings, so no user-facing HISTORY.md update is needed.)
Test Plan
request
method’s intended usage. If the library has a CI pipeline, it likely caught any downstream type errors introduced by this change.