-
Notifications
You must be signed in to change notification settings - Fork 282
fix: dialog.taro中defaultProps使用ts断言确认类型 #3347
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
Conversation
Walkthrough在 src/packages/dialog/dialog.taro.tsx 中,仅对 defaultProps 添加了类型断言,将其标注为 TaroDialogProps。未改动运行时逻辑、导出或公开 API。 Changes
Estimated code review effort🎯 1(琐碎) | ⏱️ ~2 分钟 Possibly related PRs
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/packages/dialog/dialog.taro.tsx (1)
107-116
: 覆盖 TaroDialogProps.onConfirm 类型并更新 handleOk 参数
- 在
src/types/spec/dialog/taro.ts
中,重写onConfirm
签名,支持 Taro 触摸事件和 Web 鼠标事件:export interface TaroDialogProps extends Omit<BaseDialog, 'onOverlayClick' | 'onClick'> { onConfirm?: (event: ITouchEvent | MouseEvent<HTMLButtonElement>) => PromiseLike<any> | void … }- 在
src/packages/dialog/dialog.taro.tsx
中,将handleOk
参数改为(e: ITouchEvent | MouseEvent<HTMLButtonElement>)
,以匹配上述类型。
🧹 Nitpick comments (2)
src/packages/dialog/dialog.taro.tsx (2)
22-47
: 避免 as 断言导致的类型逃逸,建议使用显式类型或显式入参类型当前用
as TaroDialogProps
会跳过对象字面量的类型校验,后续属性收敛/变更时更容易漏报。给出两种更稳妥的替代方案:
- 方案A(推荐,既保留 typeof,又保留编译期校验):为变量显式声明类型,移除断言
-const defaultProps = { +const defaultProps: TaroDialogProps = { ...defaultOverlayProps, ...defaultContentProps, ... -} as TaroDialogProps +}
- 方案B(解耦
open
的类型与defaultProps
形状):保持字面量推断并用 satisfies 做校验,同时显式标注open
入参类型-const defaultProps = { +const defaultProps = { ...defaultOverlayProps, ...defaultContentProps, ... -} as TaroDialogProps +} satisfies TaroDialogProps @@ -export function open(selector: string, options: Partial<typeof defaultProps>) { +export function open(selector: string, options: Partial<TaroDialogProps>) {
198-201
: 命名笔误:systomIcon -> systemIcon小拼写错误,影响可读性,顺手改一下更好。
- const systomIcon = closeIconPosition !== 'bottom' ? <Close /> : <Failure /> + const systemIcon = closeIconPosition !== 'bottom' ? <Close /> : <Failure /> @@ - {React.isValidElement(closeIcon) ? closeIcon : systomIcon} + {React.isValidElement(closeIcon) ? closeIcon : systemIcon}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/packages/dialog/dialog.taro.tsx
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/packages/dialog/dialog.taro.tsx (2)
src/packages/dialog/index.taro.ts (1)
TaroDialogProps
(9-9)src/types/spec/dialog/taro.ts (1)
TaroDialogProps
(8-12)
🔇 Additional comments (1)
src/packages/dialog/dialog.taro.tsx (1)
47-47
: 对齐 open 入参类型:OK将 defaultProps 断言为 TaroDialogProps 后,
typeof defaultProps
即为 TaroDialogProps,open
的第二个参数随之被推断为Partial<TaroDialogProps>
,与 PR 目标一致,且不影响运行时行为。
Dialog.open方法的第二个参数类型和dialog支持的属性不同,现修复
Summary by CodeRabbit