Skip to content

Specialize interface file types.#707

Open
viliml wants to merge 1 commit into
react-component:masterfrom
viliml:patch-1
Open

Specialize interface file types.#707
viliml wants to merge 1 commit into
react-component:masterfrom
viliml:patch-1

Conversation

@viliml
Copy link
Copy Markdown

@viliml viliml commented May 29, 2026

Files are always parsed into RcFile before being passed to these functions

Summary by CodeRabbit

  • Refactor
    • 优化了文件上传功能的类型定义,增强了代码的类型安全性和一致性,改进了基础架构的可靠性。

Review Change Stack

Files are always parsed into RcFile before being passed to these functions
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@viliml is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8eec4a65-aa69-4b29-9c70-9bf39e981997

📥 Commits

Reviewing files that changed from the base of the PR and between d53036d and 51a7811.

📒 Files selected for processing (1)
  • src/interface.tsx

概览

src/interface.tsx 中精化上传回调接口的类型定义。UploadPropsonBatchStart 回调参数中 parsedFile 字段从 Exclude<BeforeUploadFileType, boolean> 改为 RcFile;同时 UploadRequestFile 导出类型别名收窄为 RcFile,确保类型定义的一致性。

变更

上传回调类型精化

层级 / 文件 摘要
上传回调和请求文件类型精化
src/interface.tsx
onBatchStart 回调的 fileList 参数中每一项的 parsedFile 字段类型从 Exclude<BeforeUploadFileType, boolean> 精化为 RcFileUploadRequestFile 导出类型别名从联合类型 Exclude<BeforeUploadFileType, File | boolean> | RcFile 收窄为仅 RcFile,两处修改统一了文件对象类型定义。

估计审查工作量

🎯 1 (简单) | ⏱️ ~5 分钟

可能相关的 PR

  • react-component/upload#646:两个 PR 都调整了与上传文件对象相关的 TypeScript 类型定义以使用 RcFile,本 PR 更新了驱动回调参数的 UploadPropsUploadRequestFile 类型,而该 PR 更新了 beforeUpload 示例的参数和返回类型。

建议的审查者

  • yoyo837
  • zombieJ

🐰 小小类型细修缮,
RcFile 统一显清晰,
回调参数更精准,
上传流程添光彩,✨
一行一行改得妙!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确地总结了主要变更:将上传接口的文件类型从宽泛的类型定义专门化为RcFile,这是pull request的核心改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/interface.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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.

Copy link
Copy Markdown

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

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 simplifies the TypeScript definitions in src/interface.tsx by replacing complex excluded types with RcFile for onBatchStart's parsedFile and UploadRequestFile. The reviewer identified a potential runtime issue where parsedFile can be null if beforeUpload returns false, and suggested updating the type to RcFile | null to avoid TypeScript compilation failures or runtime errors.

Comment thread src/interface.tsx
multiple?: boolean;
onBatchStart?: (
fileList: { file: RcFile; parsedFile: Exclude<BeforeUploadFileType, boolean> }[],
fileList: { file: RcFile; parsedFile: RcFile }[],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

In AjaxUploader.tsx, if beforeUpload returns false, processFile returns a ParsedFileInfo object where parsedFile is null (line 212). Since onBatchStart is called with the unfiltered fileList (line 185), parsedFile can indeed be null at runtime. Typing parsedFile strictly as RcFile without allowing null can lead to runtime errors or TypeScript compilation failures in consuming applications that use strictNullChecks. We should update the type to RcFile | null to accurately reflect this possibility.

Suggested change
fileList: { file: RcFile; parsedFile: RcFile }[],
fileList: { file: RcFile; parsedFile: RcFile | null }[],

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