Skip to content

Chore: Add deep type safety for getUserByID with custom ESLint rule #2084

Merged
DonKoko merged 3 commits intomainfrom
fix-get-user-by-id-types
Oct 3, 2025
Merged

Chore: Add deep type safety for getUserByID with custom ESLint rule #2084
DonKoko merged 3 commits intomainfrom
fix-get-user-by-id-types

Conversation

@DonKoko
Copy link
Copy Markdown
Contributor

@DonKoko DonKoko commented Oct 2, 2025

Problem

TypeScript's generic constraints don't validate nested Prisma select fields.
This allowed invalid field names in nested relations to pass type checking,
causing runtime errors.

Solution

  1. Created custom ESLint rule to enforce 'satisfies Prisma.UserSelect' on
    getUserByID calls with nested selects
  2. Added satisfies annotations to all getUserByID calls with nested relations
  3. Fixed existing select clauses missing required fields

Changes

  • Add eslint-plugin-local-rules package
  • Create custom ESLint rule: require-satisfies-on-nested-prisma-selects
  • Update getUserByID documentation with deep validation examples
  • Add satisfies to getUserByID calls in:
    • _layout.tsx
    • admin-dashboard/$userId.tsx
    • onboarding.tsx
    • generate-sequential-ids.tsx
    • subscription.server.ts
  • Fix onboarding.tsx: add missing userOrganizations and businessIntel fields
  • Add defensive null check for user.roles in transfer-ownership-card.tsx
  • Update test expectations for assign-custody (select instead of include)

The ESLint rule only triggers for calls with nested selects, providing
automatic type validation without requiring extra work from developers.

DonKoko and others added 2 commits October 2, 2025 15:50
## Problem
TypeScript's generic constraints don't validate nested Prisma select fields.
This allowed invalid field names in nested relations to pass type checking,
causing runtime errors.

## Solution
1. Created custom ESLint rule to enforce 'satisfies Prisma.UserSelect' on
   getUserByID calls with nested selects
2. Added satisfies annotations to all getUserByID calls with nested relations
3. Fixed existing select clauses missing required fields

## Changes
- Add eslint-plugin-local-rules package
- Create custom ESLint rule: require-satisfies-on-nested-prisma-selects
- Update getUserByID documentation with deep validation examples
- Add satisfies to getUserByID calls in:
  - _layout.tsx
  - admin-dashboard/$userId.tsx
  - onboarding.tsx
  - generate-sequential-ids.tsx
  - subscription.server.ts
- Fix onboarding.tsx: add missing userOrganizations and businessIntel fields
- Add defensive null check for user.roles in transfer-ownership-card.tsx
- Update test expectations for assign-custody (select instead of include)

The ESLint rule only triggers for calls with nested selects, providing
automatic type validation without requiring extra work from developers.
@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shelf-docs Ignored Ignored Preview Oct 3, 2025 7:13am

@carlosvirreira
Copy link
Copy Markdown
Contributor

🔥🔥🔥

@DonKoko DonKoko merged commit 0a9d6fa into main Oct 3, 2025
6 checks passed
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.

2 participants