Skip to content
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

fix: autocomplete failed #2966

Merged
merged 3 commits into from
Feb 14, 2025
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Feb 6, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • Chores
    • 对多个组件的类型定义进行了优化,以增强类型安全性。
    • 该更新属于内部改进,不会影响现有功能或用户体验。

Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

本次 PR 修改了多个 TypeScript 文件中的类型定义。具体来说,在 image、popover、tour 和 uploader 模块中,原先允许任意字符串的类型被替换为 FixAutoComplete 类型,以提升类型精确性。所有更改均限于类型声明,不影响组件的行为、渲染逻辑或事件处理。

Changes

文件 更改摘要
src/.../image/image.tsx 更新 ImageFitImagePosition 的类型定义,移除 string,改为使用 FixAutoComplete,以增强类型安全性。
src/.../popover/popover.taro.tsx
src/.../popover/popover.tsx
修改 PopoverProps 接口中 themelocation 属性的类型,移除 string,更新为 PopoverThemePopoverLocation
src/.../tour/tour.taro.tsx
src/.../tour/tour.tsx
更新 TourProps 接口中 location 属性的类型,移除 string,更新为 PopoverLocation
src/.../uploader/types.ts 调整 FileItem 类型中 type 属性,移除 string,更新为 `FixAutoComplete<'image'
src/.../popover/types.ts 修改 PopoverThemePopoverLocation 类型定义,使用 FixAutoComplete 进行更新。
src/.../fix-string-literal-union.ts 新增 FixAutoComplete 类型别名,支持更严格的类型约束。

Suggested reviewers

  • oasis-cloud

Poem

我是跳跃的小兔子,
驰骋在代码的草原上,
类型更新如花绽放,
精确与安全手牵手,
轻舞跃步迎新光 🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

@github-actions github-actions bot added the 3.x Target branch 3.x label Feb 6, 2025
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: 0

🧹 Nitpick comments (1)
src/packages/popover/popover.taro.tsx (1)

21-24: 类型定义改进

使用 string & {} 替代 string 可以防止意外传入普通字符串,同时保持与现有代码的兼容性。这种模式在 TypeScript 中被称为"品牌类型"(branded types)。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 95c21a7 and e13181e.

📒 Files selected for processing (6)
  • src/packages/image/image.tsx (1 hunks)
  • src/packages/popover/popover.taro.tsx (1 hunks)
  • src/packages/popover/popover.tsx (1 hunks)
  • src/packages/tour/tour.taro.tsx (1 hunks)
  • src/packages/tour/tour.tsx (1 hunks)
  • src/packages/uploader/types.ts (1 hunks)
🔇 Additional comments (5)
src/packages/uploader/types.ts (1)

12-13: 类型定义优化

type 属性的类型从 string 更改为 string & {},这种改变提高了类型安全性,同时保持了向后兼容性。

src/packages/image/image.tsx (1)

47-48: 类型定义标准化

ImageFitImagePosition 类型定义的更新符合项目的类型安全标准。这种改变使得类型定义更加严格,同时保持了与其他组件的一致性。

Also applies to: 55-56

src/packages/tour/tour.tsx (1)

24-25: 接口类型优化

location 属性类型的更新提升了类型安全性,并与项目中其他组件保持一致的类型定义标准。

src/packages/tour/tour.taro.tsx (1)

25-26: Taro版本类型同步

Taro版本的 location 属性类型更新与Web版本保持一致,确保了跨平台实现的类型定义统一性。

src/packages/popover/popover.tsx (1)

24-27: 保持类型定义一致性

与 Taro 版本保持一致的类型定义改进,确保了跨平台实现的类型安全性。

建议运行以下命令验证相关组件是否都采用了相同的类型定义模式:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# 检查相关组件的类型定义
ast-grep --pattern 'interface $interface {
  $$$
  theme: $type
  $$$
}'

Length of output: 74


🏁 Script executed:

#!/bin/bash
echo "搜索所有包含统一类型定义的 'theme: PopoverTheme | (string & {})' 的出现:"
rg -o "theme:\s*PopoverTheme\s*\|\s*\(string & {}\)" -ttsx

echo "搜索所有包含统一类型定义的 'location: PopoverLocation | (string & {})' 的出现:"
rg -o "location:\s*PopoverLocation\s*\|\s*\(string & {}\)" -ttsx

Length of output: 745


🏁 Script executed:

#!/bin/bash
echo "搜索所有包含统一类型定义 'theme: PopoverTheme | (string & {})' 的出现:"
rg -o "theme:\s*PopoverTheme\s*\|\s*\\(string & \\{\\}\\)" -ttsx

echo "搜索所有包含统一类型定义 'location: PopoverLocation | (string & {})' 的出现:"
rg -o "location:\s*PopoverLocation\s*\|\s*\\(string & \\{\\}\\)" -ttsx

Length of output: 453


🏁 Script executed:

#!/bin/bash
echo "搜索所有包含统一类型定义 'theme: PopoverTheme | (string & {})' 的出现(仅在tsx文件中):"
rg -o "theme:\s*PopoverTheme\s*\|\s*\(string & \{\}\)" -g "*.tsx" .

echo "搜索所有包含统一类型定义 'location: PopoverLocation | (string & {})' 的出现(仅在tsx文件中):"
rg -o "location:\s*PopoverLocation\s*\|\s*\(string & \{\}\)" -g "*.tsx" .

Length of output: 904


类型定义一致性已验证

在以下文件中,我们检测到使用了统一的类型定义:

  • src/packages/popover/popover.tsx
  • src/packages/popover/popover.taro.tsx
  • src/packages/tour/tour.tsx
  • src/packages/tour/tour.taro.tsx

所有相关组件均采用了 PopoverTheme | (string & {})PopoverLocation | (string & {}),确保了类型定义的一致性,与 Taro 版本保持一致,也有助于维护跨平台实现的类型安全性。

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.75%. Comparing base (c2b21ba) to head (161f6bd).
Report is 12 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #2966      +/-   ##
=============================================
+ Coverage      85.74%   85.75%   +0.01%     
=============================================
  Files            277      277              
  Lines          18110    18110              
  Branches        2745     2735      -10     
=============================================
+ Hits           15528    15531       +3     
+ Misses          2577     2574       -3     
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/packages/image/image.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the action:review This PR needs more reviews (less than 2 approvals) label Feb 13, 2025
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: 0

🧹 Nitpick comments (2)
src/types/fix-string-literal-union.ts (1)

1-2: ESLint 规则禁用说明需要更详细

建议在注释中说明为什么需要禁用这条规则,以便其他开发者理解。

-// eslint-disable-next-line @typescript-eslint/ban-types
+// eslint-disable-next-line @typescript-eslint/ban-types
+// 这里禁用规则是因为我们需要使用 {} 来修复字符串字面量联合类型的自动完成功能
src/packages/popover/types.ts (1)

4-17: 位置类型定义完整且清晰

PopoverLocation 类型定义涵盖了所有可能的弹出位置,包括基础方位和细分位置,结构清晰。建议添加类型说明文档。

+/**
+ * 弹出层位置类型
+ * @property bottom - 下方居中
+ * @property top - 上方居中
+ * @property left - 左侧居中
+ * @property right - 右侧居中
+ * @property top-start - 上方左对齐
+ * @property top-end - 上方右对齐
+ * ...
+ */
 export type PopoverLocation = FixAutoComplete<
   | 'bottom'
   | 'top'
   // ...
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e13181e and 161f6bd.

📒 Files selected for processing (8)
  • src/packages/image/image.tsx (2 hunks)
  • src/packages/popover/popover.taro.tsx (1 hunks)
  • src/packages/popover/popover.tsx (1 hunks)
  • src/packages/popover/types.ts (2 hunks)
  • src/packages/tour/tour.taro.tsx (1 hunks)
  • src/packages/tour/tour.tsx (1 hunks)
  • src/packages/uploader/types.ts (2 hunks)
  • src/types/fix-string-literal-union.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/packages/tour/tour.taro.tsx
  • src/packages/tour/tour.tsx
  • src/packages/uploader/types.ts
  • src/packages/popover/popover.tsx
  • src/packages/image/image.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (4)
src/types/fix-string-literal-union.ts (1)

2-2: 类型定义实现正确

这个类型定义很好地解决了字符串字面量联合类型的自动完成问题。通过将原始类型与 string & {} 联合,既保留了类型约束又支持了自动完成功能。

src/packages/popover/types.ts (1)

3-3: 主题类型定义优化合理

使用 FixAutoComplete 改进 PopoverTheme 类型定义,既保持了类型安全性又提供了更好的开发体验。

src/packages/popover/popover.taro.tsx (2)

21-22: 接口类型约束增强

移除了 themelocation 属性中的 string 联合类型,使用 PopoverThemePopoverLocation 类型,提高了类型安全性。


43-60:

❓ Verification inconclusive

验证默认属性值的类型兼容性

请确保 defaultProps 中的 themelocation 的默认值与更新后的类型定义兼容。


🏁 Script executed:

#!/bin/bash
# 检查 theme 和 location 的默认值是否符合类型定义
ast-grep --pattern 'theme: $value' src/packages/popover/types.ts
ast-grep --pattern 'location: $value' src/packages/popover/types.ts

Length of output: 136


请手动确认默认属性与类型定义的匹配性

请在 src/packages/popover/types.ts 文件中检查 themelocation 的类型定义,确保它们允许默认值 'light''bottom'。如果类型定义中允许的值范围不同,请相应更新默认值或调整类型定义。

@oasis-cloud oasis-cloud merged commit d07e815 into jdf2e:feat_v3.x Feb 14, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants