Skip to content

refactor(components): [switch] use type-based definitions#23420

Merged
btea merged 2 commits into
element-plus:devfrom
lw56777:refactor/switch-ComponentProps-#23399
Jan 18, 2026
Merged

refactor(components): [switch] use type-based definitions#23420
btea merged 2 commits into
element-plus:devfrom
lw56777:refactor/switch-ComponentProps-#23399

Conversation

@lw56777
Copy link
Copy Markdown
Contributor

@lw56777 lw56777 commented Jan 17, 2026

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

修复:#23399

Summary by CodeRabbit

  • Refactor
    • Improved Switch component prop typing with a clear public interface and component-level default values; deprecation wrappers added to preserve runtime behavior.
  • Chores
    • Replaced the older public prop alias with a new preferred type and marked the legacy public alias as deprecated.

✏️ Tip: You can customize this high-level summary in your review settings.

@pull-request-triage
Copy link
Copy Markdown

👋 @lw56777, seems like this is your first time contribution to element-plus.
Please make sure that you have read our guidelines and code of conduct before making a contribution.

@pull-request-triage pull-request-triage Bot added 1st contribution Their very first contribution Needs Review labels Jan 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 17, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Replaces prop-object-based public typing with an explicit SwitchProps interface and a deprecated SwitchPropsPublic alias; component uses defineProps<SwitchProps>() with withDefaults, and imports/types updated accordingly across the Switch component files.

Changes

Cohort / File(s) Summary
Switch Type Definition
packages/components/switch/src/switch.ts
Adds explicit export interface SwitchProps listing all public props; introduces deprecated export type SwitchPropsPublic = ExtractPublicPropTypes<typeof switchProps>; retains switchProps and switchEmits but marks prior public aliases deprecated; updates Vue type imports.
Switch Component Implementation
packages/components/switch/src/switch.vue
Changes prop usage from defineProps(switchProps) to withDefaults(defineProps<SwitchProps>(), {...}); imports type { SwitchProps } instead of runtime switchProps; applies explicit default values in the component.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • keeplearning66
  • rzzf
  • btea

Poem

🐰 I hopped through code with careful paws,
Typed a Switch without old clause,
Defaults tucked in snug and neat,
Deprecated notes soft and sweet,
Hooray—this rabbit’s done the cause! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main refactoring change: switching the Switch component to use type-based definitions instead of prop object definitions.
Description check ✅ Passed The description includes checked items confirming compliance with contributing guidelines, proper branch targeting, and issue reference (#23399), meeting the template requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 17, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus/element-plus@23420
npm i https://pkg.pr.new/element-plus/element-plus@23420
yarn add https://pkg.pr.new/element-plus/[email protected]

commit: 93be3a1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 17, 2026

🧪 Playground Preview: https://element-plus.run/?pr=23420
Please comment the example via this playground if needed.

Comment thread packages/components/switch/src/switch.vue
@btea btea merged commit 159f4a8 into element-plus:dev Jan 18, 2026
17 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@lw56777 Thanks for your contribution! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants