Skip to content

feat(types): add LiteralUnion type and refactor union types - #128

Merged
chenjiahan merged 1 commit into
mainfrom
literal_union_type_0305
Mar 5, 2026
Merged

chenjiahan merged 1 commit into
mainfrom
literal_union_type_0305

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Use LiteralUnion type to simplify and standardize string literal unions with fallback to string type. This improves type safety and maintainability while following TypeScript best practices.

Copilot AI review requested due to automatic review settings March 5, 2026 04:07
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the type definitions within the project by introducing and applying a LiteralUnion utility type. This change standardizes how string literal unions are defined, allowing for specific literal values while gracefully falling back to a broader string type. The primary impact is improved type safety, better maintainability, and clearer intent in the codebase's TypeScript definitions, aligning with best practices for flexible yet strict typing.

Highlights

  • New LiteralUnion Type: Introduced a new LiteralUnion utility type to handle string literal unions with a fallback to a generic string type, improving type safety and flexibility.
  • Type Refactoring: Refactored several existing type definitions across src/server.ts and src/types.ts to utilize the new LiteralUnion type, including allowedHosts, webSocketServer, Host, Port, ServerType, WebSocketServerConfiguration.type, and ClientConfiguration.webSocketTransport.
  • Documentation Update: Updated a link in the README.md file to point to the correct v1.x documentation for rspack-dev-server.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • README.md
    • Updated the link for the v1.x README to include the specific anchor for rspack-dev-server.
  • src/server.ts
    • Imported the new LiteralUnion type.
    • Applied LiteralUnion to the allowedHosts property in the Configuration interface.
    • Applied LiteralUnion to the webSocketServer property in the Configuration interface.
  • src/types.ts
    • Defined the LiteralUnion utility type, referencing a TypeScript issue for context.
    • Refactored the Host type to use LiteralUnion for 'local-ip', 'local-ipv4', 'local-ipv6' with a string fallback.
    • Refactored the Port type to use LiteralUnion for 'auto' with a string fallback.
    • Refactored the ServerType type to use LiteralUnion for 'http', 'https', 'http2' with a string fallback.
    • Refactored the type property within WebSocketServerConfiguration to use LiteralUnion for 'ws' with a string fallback.
    • Refactored the webSocketTransport property within ClientConfiguration to use LiteralUnion for 'ws' with a string fallback.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the LiteralUnion utility type to improve autocompletion for string literal union types throughout the codebase. The refactoring is applied consistently to configuration options like allowedHosts, webSocketServer, Host, Port, and others, enhancing developer experience without changing runtime behavior. The implementation is clean and follows TypeScript best practices for this pattern. The change to README.md also correctly updates a link to point to a specific section. Overall, the changes are solid and beneficial.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a reusable LiteralUnion helper type to improve IntelliSense/type-safety for string literal unions (while still allowing arbitrary strings), and applies it across the dev-server public types.

Changes:

  • Add LiteralUnion type helper in src/types.ts.
  • Refactor several string-literal-or-string unions (Host, Port, ServerType, websocket/client transports, allowedHosts) to use LiteralUnion.
  • Update the README link for the v1.x usage guide anchor.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/types.ts Adds LiteralUnion and refactors multiple exported type unions to use it.
src/server.ts Updates the exported Configuration interface to use LiteralUnion for allowedHosts and websocket configuration types.
README.md Fixes/updates the v1.x README link to a more specific anchor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/server.ts
Comment thread src/types.ts
@chenjiahan
chenjiahan merged commit 44b2ed4 into main Mar 5, 2026
7 checks passed
@chenjiahan
chenjiahan deleted the literal_union_type_0305 branch March 5, 2026 04:16
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