-
Notifications
You must be signed in to change notification settings - Fork 1
Accepts string to body #109
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
Conversation
WalkthroughThe changes involve modifications to type definitions across several files, primarily focusing on the 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
CodeRabbit Configuration File (
|
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- src/common/spec.ts (1 hunks)
- src/fetch/index.t-test.ts (1 hunks)
- src/fetch/index.ts (2 hunks)
Additional context used
Biome
src/fetch/index.ts
[error] 37-37: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
Additional comments not posted (2)
src/common/spec.ts (1)
61-62: Approve the changes to theBodytype in theApiSpecinterface.The changes to the
Bodytype in theApiSpecinterface are a good improvement. By expanding the type to accept either a record of string keys with any values or a string, it allows for more flexibility in the types of data that can be passed as the request body in API specifications.This change may require updates to existing code that uses the
ApiSpecinterface to ensure type compatibility. Please ensure that all relevant code has been updated to handle the newBodytype correctly.Additionally, the removal of the ESLint disable comment for the explicit
anytype suggests that the codebase's linting rules have been updated to allow explicitanytypes in certain contexts. Please ensure that this change aligns with the project's coding standards and guidelines.src/fetch/index.ts (1)
24-24: Modification ofHeadersObjto includestringis appropriate.The addition of
stringto theHeadersObjtype parameter enhances flexibility, allowing headers to be provided as a raw string in addition to an object.
src/fetch/index.t-test.ts
Outdated
| }>; | ||
| (async () => { | ||
| const f = fetch as FetchT<"", Spec>; | ||
| await f(`/users`, { method: "post" }); |
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.
Add the request body in the fetch call.
The Spec type defines the request body as a string for the POST request to the "/users" endpoint. However, the fetch call in the test case does not provide the required request body.
To properly test the API endpoint and align with the defined Spec type, add the request body in the fetch call:
-await f(`/users`, { method: "post" });
+await f(`/users`, { method: "post", body: "request body string" });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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| await f(`/users`, { method: "post" }); | |
| await f(`/users`, { method: "post", body: "request body string" }); |
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 UI
Review profile: CHILL
Files selected for processing (3)
- src/common/spec.ts (2 hunks)
- src/fetch/index.t-test.ts (1 hunks)
- src/fetch/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/common/spec.ts
- src/fetch/index.t-test.ts
Additional context used
Biome
src/fetch/index.ts
[error] 37-37: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
Additional comments not posted (1)
src/fetch/index.ts (1)
23-24: LGTM: Enhanced flexibility for Body and HeadersObj typesThe changes to include
stringas a possible type for bothBodyandHeadersObjimprove the flexibility of theRequestInitTtype. This aligns well with the PR objective of accepting strings for the body and enhances the overall usability of the type definition.
| : Body extends string | ||
| ? { body: string } | ||
| : // eslint-disable-next-line @typescript-eslint/ban-types | ||
| {}) & |
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.
Approve new condition, but address remaining type issue
The new condition for handling string body types is a good addition and aligns well with the changes made to the Body type parameter. However, the use of {} as a type is still present and should be addressed.
Please apply the following change to address the remaining type issue:
: Body extends string
? { body: string }
: // eslint-disable-next-line @typescript-eslint/ban-types
- {})
+ Record<string, never>)This change replaces {} with Record<string, never>, providing a more precise empty object type and complying with linter rules.
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. Thoroughly test & benchmark the code to ensure it meets the requirements.
| : Body extends string | |
| ? { body: string } | |
| : // eslint-disable-next-line @typescript-eslint/ban-types | |
| {}) & | |
| : Body extends string | |
| ? { body: string } | |
| : // eslint-disable-next-line @typescript-eslint/ban-types | |
| Record<string, never>) & |
Tools
Biome
[error] 37-37: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
Summary by CodeRabbit
New Features
"/users"POST method.Bug Fixes
Documentation
anytypes.