-
-
Notifications
You must be signed in to change notification settings - Fork 28
fix: improve type inference for array of enums #437
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
Enhances type inference for arrays of enums in the TypeScript generation logic, ensuring that it correctly expands to the enum's members instead of defaulting to `unknown[]`. Additionally, adds testing guidelines for running tests in the project.
🦋 Changeset detectedLatest commit: 1dd9be2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 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 GitHub. |
|
Warning Rate limit exceeded@Newbie012 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 42 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe changes implement a fix for inferring array enum types during code generation. A new Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
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/generate/src/generate.ts (1)
461-496: LGTM!The enum resolution logic correctly implements the two-stage lookup:
- Direct enum lookup by OID
- Fallback to array element enum via
typelemThe implementation is consistent with
ast-describe.ts.Consider extracting the
getEnumByOidandvalueAsEnumlogic into a shared utility function to avoid duplication betweengenerate.tsandast-describe.ts. Both files implement nearly identical logic for enum resolution.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/fancy-chefs-cough.md.cursor/rules/testing.mdcpackages/generate/src/ast-describe.tspackages/generate/src/generate.test.tspackages/generate/src/generate.ts
🔇 Additional comments (8)
.cursor/rules/testing.mdc (1)
1-29: LGTM!The testing guidelines are clear and provide a useful reference for running Vitest tests in the monorepo structure. The step-by-step workflow and example command are helpful for developers.
.changeset/fancy-chefs-cough.md (1)
1-6: LGTM!The changeset correctly identifies both affected packages and accurately describes the fix for array enum inference.
packages/generate/src/generate.test.ts (1)
2486-2510: LGTM!The test case effectively validates the new array enum inference feature. The expected output structure correctly represents an array containing a union of the enum's string literal members, which aligns with the implementation changes in
ast-describe.tsandgenerate.ts.packages/generate/src/ast-describe.ts (3)
117-127: LGTM!Good refactor to retrieve
pgTypeearly and use it for thetypefield. The optional chaining with fallback to"unknown"handles missing types gracefully.
140-180: LGTM!The two-stage enum resolution logic is well-structured:
- Direct enum lookup by OID
- Fallback to array element enum when
typelemis present and non-zeroThe use of
satisfies ASTDescribedColumnTypeensures type safety for the array wrapper.
187-187: LGTM!Consistent use of
pgType?.namefor the type field with proper fallback.packages/generate/src/generate.ts (2)
627-631: LGTM!The
typelemfield is correctly typed asnumber(PostgreSQL OID type). This field contains the element type OID for array types, which is essential for the array enum resolution.
635-638: LGTM!The SQL query correctly fetches
typelemfrompg_type. This is a standard PostgreSQL catalog column that stores the OID of the element type for array types.
Enhances type inference for arrays of enums in the TypeScript generation logic, ensuring that it correctly expands to the enum's members instead of defaulting to
unknown[]. Additionally, adds testing guidelines for running tests in the project.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.