-
Notifications
You must be signed in to change notification settings - Fork 269
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
fix: autocomplete failed #2966
Conversation
Walkthrough本次 PR 修改了多个 TypeScript 文件中的类型定义。具体来说,在 image、popover、tour 和 uploader 模块中,原先允许任意字符串的类型被替换为 Changes
Suggested reviewers
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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
: 类型定义标准化
ImageFit
和ImagePosition
类型定义的更新符合项目的类型安全标准。这种改变使得类型定义更加严格,同时保持了与其他组件的一致性。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 & {}\)" -ttsxLength 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 & \\{\\}\\)" -ttsxLength 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 版本保持一致,也有助于维护跨平台实现的类型安全性。
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this 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
📒 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
: 接口类型约束增强移除了
theme
和location
属性中的string
联合类型,使用PopoverTheme
和PopoverLocation
类型,提高了类型安全性。
43-60
:❓ Verification inconclusive
验证默认属性值的类型兼容性
请确保
defaultProps
中的theme
和location
的默认值与更新后的类型定义兼容。
🏁 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.tsLength of output: 136
请手动确认默认属性与类型定义的匹配性
请在
src/packages/popover/types.ts
文件中检查theme
与location
的类型定义,确保它们允许默认值'light'
和'bottom'
。如果类型定义中允许的值范围不同,请相应更新默认值或调整类型定义。
🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
☑️ 请求合并前的自查清单
Summary by CodeRabbit