fix(codegen): narrow generateEndpoints return type#5237
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ac807c3:
|
There was a problem hiding this comment.
Pull request overview
This PR is a follow-up change in @rtk-query/codegen-openapi to improve the TypeScript ergonomics of generateEndpoints by narrowing its return type based on whether outputFile is provided, eliminating the need for consumer-side type assertions.
Changes:
- Add overload signatures for
generateEndpointsto returnPromise<string>whenoutputFileis omitted, andPromise<void>whenoutputFileis provided. - Add runtime + type-level tests validating the new narrowing behavior (including
*.test-d.tstypecheck coverage). - Update Vitest-related dependencies / configuration to support the added typecheck tests.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Updates Vitest (and related deps) used by the repo/test setup. |
| packages/rtk-query-codegen-openapi/vitest.config.mts | Adjusts Vitest config (including enabling typecheck) to support the new type tests. |
| packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts | Adds runtime assertions for returned value shape with/without outputFile. |
| packages/rtk-query-codegen-openapi/test/generateEndpoints.test-d.ts | Adds type-level tests asserting overload-based return type narrowing. |
| packages/rtk-query-codegen-openapi/src/index.ts | Introduces the overload signatures for generateEndpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6b396d3 to
bcc6556
Compare
bcc6556 to
537a56b
Compare
422abe6 to
ffc50d6
Compare
ffc50d6 to
5f07afe
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Issy Szemeti <48881813+issy@users.noreply.github.com>
5f07afe to
ac807c3
Compare
Summary
exactOperationIdsoption togenerateEndpointsconfig #5174.generateEndpointsso the return type narrows based on whetheroutputFileis provided:outputFile→Promise<string>outputFile→Promise<void>This eliminates the need for manual type assertions like
await generateEndpoints(...) as stringin consumer code.