Skip to content

feat(server): enhance ts error for .use #277

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

Merged
merged 5 commits into from
Mar 21, 2025
Merged

Conversation

unnoq
Copy link
Owner

@unnoq unnoq commented Mar 21, 2025

BEFORE: The .use method might return never if the required conditions are not met;
NOW: it throw a TypeScript error to indicate the issue.

Summary by CodeRabbit

  • Refactor

    • Streamlined middleware and procedure method signatures to enhance type safety and flexibility.
    • Removed redundant types and constructs for a cleaner, more maintainable internal API.
    • Introduced a new type alias IntersectPick to facilitate type intersections.
  • Tests

    • Updated error handling annotations to clearly indicate expected TypeScript errors, resulting in more concise tests.
    • Added new unit tests for utility types to ensure type correctness.
  • Chores

    • Cleaned up unused type definitions and import statements to improve overall code maintainability.

Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 6:28am

Copy link

codecov bot commented Mar 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

pkg-pr-new bot commented Mar 21, 2025

Open in Stackblitz

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@277

@orpc/client

npm i https://pkg.pr.new/@orpc/client@277

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@277

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@277

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@277

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@277

@orpc/server

npm i https://pkg.pr.new/@orpc/server@277

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@277

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@277

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@277

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@277

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@277

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@277

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@277

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@277

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@277

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@277

commit: e3b3fc5

Copy link

coderabbitai bot commented Mar 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request makes extensive changes to the TypeScript type assertions and method signatures across several server and shared packages. It replaces runtime type equality checks (using expectTypeOf) with inline TypeScript error expectations (@ts-expect-error), streamlines middleware and procedure builder interfaces by accepting union types (e.g., UInContext | TCurrentContext), and removes the now redundant ContextExtendsGuard type. A new helper type IntersectPick is also introduced to refine type constraints. These modifications affect both test files and core implementation files without altering the underlying runtime behavior.

Changes

Files Change Summary
server/src/builder-variants.test-d.ts, server/src/builder.test-d.ts, server/src/implementer-procedure.test-d.ts, server/src/implementer-variants.test-d.ts, server/src/implementer.test-d.ts, server/src/middleware-decorated.test-d.ts, server/src/procedure-decorated.test-d.ts Replaced expectTypeOf assertions with @ts-expect-error comments and simplified error annotations for invalid context types in tests.
server/src/builder-variants.ts, server/src/builder.ts Updated use and middleware method signatures to accept a union type (`UInContext
server/src/context.ts, server/src/context.test-d.ts Removed the ContextExtendsGuard type definition and its related tests.
server/src/implementer-procedure.ts, server/src/procedure-decorated.ts Modified use method signatures to use IntersectPick<TCurrentContext, UOutContext> for output contexts and to allow union types for input contexts, thereby streamlining type constraints.
server/src/implementer-variants.ts, server/src/implementer.ts Removed unused ContextExtendsGuard, updated import statements, and simplified method signatures by replacing ORPCErrorConstructorMap<any> with any.
server/src/middleware-decorated.ts Altered the concat method signature in DecoratedMiddleware to allow union types for UInContext and removed the ContextExtendsGuard from the return type.
shared/src/types.ts Added a new type alias: export type IntersectPick<T, U> = Pick<T, keyof T & keyof U>.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant B as Builder
    participant MW as Middleware
    Dev->>B: Call use(middleware)
    alt Valid Middleware
        B->>MW: Process middleware with (UInContext | TCurrentContext)
        B-->>Dev: Return updated Builder instance
    else Invalid Middleware
        B-->>Dev: Compiler error (@ts-expect-error expected)
    end
Loading
sequenceDiagram
    participant Dev as Developer
    participant I as Implementer/Procedure
    participant MW as Middleware
    Dev->>I: Invoke use(middleware)
    I->>I: Validate context (using IntersectPick & union types)
    I->>MW: Process middleware accordingly
    I-->>Dev: Return updated implementation instance
Loading

Possibly related PRs

Poem

I'm a coding rabbit, hopping with delight,
@ts-expect-error now guides my code just right.
Streams of middleware flow, simple and clear,
Type guards shed, no more extra fear.
In this code garden, every type is aligned—
Hoppy cheers and carrots, for a design refined!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb68b0 and e3b3fc5.

📒 Files selected for processing (1)
  • packages/shared/src/types.test-d.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
packages/shared/src/types.test-d.ts (1)

29-29: Consider using a type alias instead of an empty interface.

An empty interface is equivalent to {}. Using a type alias would be more idiomatic and clearer.

-interface Empty {}
+type Empty = {};
🧰 Tools
🪛 Biome (1.9.4)

[error] 28-29: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a18ba0e and 2cb68b0.

📒 Files selected for processing (1)
  • packages/shared/src/types.test-d.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/shared/src/types.test-d.ts

[error] 28-29: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

🔇 Additional comments (1)
packages/shared/src/types.test-d.ts (1)

1-36: Well-structured tests for utility types.

The tests are comprehensive and validate the behavior of the utility types effectively. This is especially important for IntersectPick which appears to be a new addition that supports the enhanced TS error handling for the .use method as mentioned in the PR objectives.

🧰 Tools
🪛 Biome (1.9.4)

[error] 28-29: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

@unnoq unnoq merged commit c0dd7cd into main Mar 21, 2025
4 of 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.

1 participant