select icon indicating copy to clipboard operation
select copied to clipboard

fix: add `undefined` to optional `className` properties (fixes #1143)

Open junhaoliao opened this issue 10 months ago • 5 comments

With a reference to https://www.github.com/DefinitelyTyped/DefinitelyTyped/pull/54352, this PR addresses a TypeScript error that occurs when using rc-select with CSS Modules in a Vite project with exactOptionalPropertyTypes: true enabled.

Summary by CodeRabbit

  • 重构
    • 此次更改显式地在 BaseSelectProps 接口和 BaseOptionType 接口中将 classNamepopupClassName 两个可选字符串属性的类型声明从隐式的可选(string 或未声明)改为显式包含 undefinedstring | undefined)。这些修改仅调整了类型注解的明确性,不影响运行时行为或逻辑。

junhaoliao avatar Apr 10 '25 01:04 junhaoliao

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 7:26am

vercel[bot] avatar Apr 10 '25 01:04 vercel[bot]

## Walkthrough
此次更改显式地在 `BaseSelectProps` 接口和 `BaseOptionType` 接口中将 `className` 和 `popupClassName` 两个可选字符串属性的类型声明从隐式的可选(`string` 或未声明)改为显式包含 `undefined`(`string | undefined`)。这些修改仅调整了类型注解的明确性,不影响运行时行为或逻辑。

## Changes
| 文件                           | 更改说明                                                                                  |
|------------------------------|-------------------------------------------------------------------------------------------|
| `src/BaseSelect/index.tsx` 和 `src/Select.tsx` | 在接口 `BaseSelectProps` 和 `BaseOptionType` 中,将 `className` 和 `popupClassName` 属性的类型由隐式可选的 `string` 改为显式包含 `undefined` 的 `string | undefined`。 |

## Possibly related PRs
- **react-component/select#1133**: 此 PR 同样涉及对 `BaseSelectProps` 接口的更新,直接修改了属性声明,与本次改动存在代码层面的联系。

## Suggested reviewers
- zombieJ

## Poem
> 我是小兔跳跃忙,  
> 代码更新乐无疆,  
> 类型声明更明确,  
> 细节变化藏光芒,  
> 小改动也辉煌,  
> 跟我一起欢歌唱! 🐇

[!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/Select.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js Error: Cannot find module '@umijs/fabric/dist/eslint' Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15) at Module._load (node:internal/modules/cjs/loader:1074:27) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:217:24) at Module.require (node:internal/modules/cjs/loader:1339:12) at require (node:internal/modules/helpers:135:16) at Object. (/.eslintrc.js:1:14) at Module._compile (node:internal/modules/cjs/loader:1546:14) at Module._extensions..js (node:internal/modules/cjs/loader:1691:10) at Module.load (node:internal/modules/cjs/loader:1317:32)
src/BaseSelect/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js Error: Cannot find module '@umijs/fabric/dist/eslint' Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15) at Module._load (node:internal/modules/cjs/loader:1074:27) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:217:24) at Module.require (node:internal/modules/cjs/loader:1339:12) at require (node:internal/modules/helpers:135:16) at Object. (/.eslintrc.js:1:14) at Module._compile (node:internal/modules/cjs/loader:1546:14) at Module._extensions..js (node:internal/modules/cjs/loader:1691:10) at Module.load (node:internal/modules/cjs/loader:1317:32)

📜 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 55e35d60ca9d0cc17d54e0d836b05c2727a3151a and 86787f5f69a13c523d71ef37c7e330b86c79c1f7.

📒 Files selected for processing (2)
  • src/BaseSelect/index.tsx (2 hunks)
  • src/Select.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/BaseSelect/index.tsx
🔇 Additional comments (1)
src/Select.tsx (1)

93-93: 修复了 TypeScript 类型定义,使其更加明确。

通过将 className 的类型从隐式的可选 string 更改为显式的 string | undefined,此更改解决了在启用 TypeScript 的 exactOptionalPropertyTypes: true 编译器选项时出现的类型错误。这是一个好的修复,因为它不会影响运行时行为或逻辑,但提高了与特定 TypeScript 配置的兼容性。

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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
🪧 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.

coderabbitai[bot] avatar Apr 10 '25 01:04 coderabbitai[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.26%. Comparing base (3639a8a) to head (86787f5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1144   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files          39       39           
  Lines        1500     1500           
  Branches      453      425   -28     
=======================================
  Hits         1474     1474           
  Misses         26       26           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Apr 22 '25 07:04 codecov[bot]

@zombieJ 你好,打扰了,方便的时候能否帮忙看一下这个PR的改动?这些更改是参考了https://www.github.com/DefinitelyTyped/DefinitelyTyped/pull/54352 这个PR做的。理论上我们可以针对所有的可选属性加入显式的 undefined 声明,不过我不太确定这样是否改动过多。还请指教,这个PR是否需要包含所有相关的修改?谢谢!

junhaoliao avatar Apr 22 '25 07:04 junhaoliao

是否能提供一个重现?感觉这个改动好像没什么意义??: 自带了 undefined

afc163 avatar May 07 '25 11:05 afc163