Skip to content

Fix strict select subset typing under TS6#2720

Open
olup wants to merge 1 commit into
zenstackhq:devfrom
olup:codex/fix-select-subset-ts6
Open

Fix strict select subset typing under TS6#2720
olup wants to merge 1 commit into
zenstackhq:devfrom
olup:codex/fix-select-subset-ts6

Conversation

@olup

@olup olup commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a TypeScript 6 / tsgo typing gap where direct client calls accepted unknown nested keys in select objects, even though the explicit args type rejected them.

The issue was reported in #2719.

What changed

  • Tightened SelectSubset for select, include, and omit properties so nested keys are checked against the contextual argument shape.
  • Added a regression typecheck for unknown select fields on direct client calls.
  • Marked existing slicing / unsupported-field runtime validation cases with @ts-expect-error, matching their comments and the now-stricter compile-time behavior.

Validation

  • pnpm --filter @zenstackhq/orm build
  • pnpm --filter e2e test:typecheck

Created by Codex on human request.

Summary by CodeRabbit

Release Notes

  • Refactor

    • Enhanced TypeScript validation for ORM select, include, and omit parameters to enforce stricter type checking, preventing selection of invalid fields and access to unselected properties.
  • Tests

    • Updated test suite with comprehensive type-checking assertions to validate stricter parameter validation behavior and ensure proper error detection.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5904f557-d4f3-4291-9cb4-4e782d76c58a

📥 Commits

Reviewing files that changed from the base of the PR and between d229533 and f5fa064.

📒 Files selected for processing (4)
  • packages/orm/src/client/crud-types.ts
  • tests/e2e/orm/client-api/slicing.test.ts
  • tests/e2e/orm/client-api/unsupported.test.ts
  • tests/e2e/orm/schemas/typing/typecheck.ts

📝 Walkthrough

Walkthrough

SelectSubset<T, U> is rewritten to introduce three helper types (NoExtraKeys, PreserveNullish, StrictArgProperty) that forbid extra keys and preserve nullishness specifically for select, include, and omit properties. E2e tests in slicing, unsupported, and typecheck files are updated with // @ts-expect-error`` annotations that assert the new compile-time errors.

Changes

SelectSubset strict typing and test coverage

Layer / File(s) Summary
SelectSubset helper types and rewrite
packages/orm/src/client/crud-types.ts
Adds NoExtraKeys, PreserveNullish, and StrictArgProperty helper conditional types, then replaces SelectSubset to apply strict no-extra-keys and nullishness-preserving logic only for select, include, and omit keys, while leaving other overlapping properties as-is.
E2e ts-expect-error annotations
tests/e2e/orm/schemas/typing/typecheck.ts, tests/e2e/orm/client-api/slicing.test.ts, tests/e2e/orm/client-api/unsupported.test.ts
Adds // @ts-expect-error`` annotations asserting TypeScript errors for: unselected field access after findUniqueOrThrow, an invalid `missingField` in `findMany` select, excluded model selects in slicing tests, and an unsupported `data` field in select.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 A rabbit once typed select: { name: true },
But slipped in a field that nobody knew.
With NoExtraKeys now standing guard,
The compiler said "Nope!" and played its card.
Type errors rejoice — strict rules are the way!
Extra keys begone, hip hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: fixing strict select subset typing for TypeScript 6, which is the core improvement described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant