chore: remove unnecessary type assertions#5802
Merged
chenjiahan merged 2 commits intomainfrom Aug 9, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes unnecessary type assertions from the codebase and re-enables the corresponding ESLint rule. The changes improve type safety by relying on TypeScript's inference rather than explicit assertions.
- Removed the ESLint rule exception for
@typescript-eslint/no-unnecessary-type-assertion - Eliminated type assertions where TypeScript can infer the correct types
- Removed unused type imports that were only needed for the assertions
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rslint.json | Re-enabled the no-unnecessary-type-assertion ESLint rule |
| packages/plugin-vue/src/splitChunks.ts | Removed type assertion and unused import |
| packages/plugin-react/src/splitChunks.ts | Removed type assertion and unused import |
| packages/core/src/server/runner/esm.ts | Removed non-null assertions on file parameter |
| packages/core/src/server/runner/basic.ts | Removed non-null assertion on array access |
| const p = Array.isArray(modulePath) | ||
| ? modulePath | ||
| : modulePath.split('?')[0]!; | ||
| : modulePath.split('?')[0]; |
There was a problem hiding this comment.
Removing the non-null assertion here could cause a runtime error. The split('?')[0] operation could return undefined if the array is empty, which would break the subsequent code. Consider adding proper validation or keeping the assertion with a runtime check.
Suggested change
| : modulePath.split('?')[0]; | |
| : (typeof modulePath === 'string' ? (modulePath.split('?')[0] ?? '') : ''); |
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
@typescript-eslint/no-unnecessary-type-assertioninrslint.jsonChecklist