Skip to content

fix: export SwitchProps - #181

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/export-switch-props
Open

fix: export SwitchProps#181
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/export-switch-props

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 27, 2026

Copy link
Copy Markdown

Summary

  • export the existing SwitchProps interface from the package entry point
  • add a compile-time consumer test for the named type export and its onChange inference

Closes #57.
Supersedes #56, whose 2020 branch is now conflicting and more than 50 commits behind the current implementation.

Why

Consumers that export a styled or wrapped Switch can otherwise hit TypeScript TS4023 because the generated public component type refers to a private, unnameable SwitchProps. The runtime API does not change; this only makes the interface already present in the emitted declaration nameable by consumers.

Verification

Before the implementation change, the new type test fails on current master with:

TS2614: Module '"@rc-component/switch"' has no exported member 'SwitchProps'.

After the change:

  • npm run tsc
  • npm test -- --runInBand — 14/14 tests
  • npm run lint — no errors; one pre-existing unused-disable warning in docs/examples/simple.tsx
  • npm run compile — ESM, CJS, and declarations generated successfully
  • npx prettier --check src/index.tsx tests/type.tsx
  • verified both generated es/index.d.ts and lib/index.d.ts contain export interface SwitchProps

AI assistance disclosure: Codex was used to inspect current issue/PR overlap, prepare the type regression, and run validation. I verified the exact-base failure, final diff, generated declarations, and all results above.

Summary by CodeRabbit

  • 新功能

    • 导出 SwitchProps 类型,便于在项目中复用和进行类型检查。
  • 测试

    • 新增编译期类型检查,验证开关组件属性定义可正常使用。
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2db419b-41f6-4326-a5ea-314c74289c6b

📥 Commits

Reviewing files that changed from the base of the PR and between ac3c285 and c0751a9.

📒 Files selected for processing (2)
  • src/index.tsx
  • tests/type.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

SwitchProps 接口现已作为公共类型导出。新增类型测试,用于验证 checked 属性和 onChange 回调的类型推断。

Changes

SwitchProps 公共类型

Layer / File(s) Summary
导出并验证 SwitchProps
src/index.tsx, tests/type.tsx
SwitchProps 接口现在可导出。新增测试导入该接口,并检查 checkedonChange 的类型。

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to c0751

This change exposes the existing SwitchProps type for consumers and adds coverage for its named export and onChange inference without changing runtime behavior. No actionable merge-blocking risk remains after normal checks and review.

Poem

小兔打开类型门,
SwitchProps 跳出来,
checked 穿上布尔鞋,
onChange 轻声应答,
编译检查拍拍手。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题“fix: export SwitchProps”准确概括了主要改动。标题简洁明确,开发者可以快速理解该 PR 的核心目的。
Linked Issues check ✅ Passed PR 满足 #57 的全部编码需求。PR 将 SwitchProps 接口从未导出改为导出,解决了 TypeScript 用户在使用 styled-components 或其他包装器时遇到的 TS4023 错误。PR 还添加了编译时类型检查测试,用于验证导出的 SwitchProps 类型和 onChange 类型推导。PR 目标与 #57 完全对应。
Out of Scope Changes check ✅ Passed 所有代码改动均在 PR 范围内。src/index.tsx 仅修改了 SwitchProps 接口的可见性。新增的 tests/type.tsx 专门验证 SwitchProps 导出和类型推导。两处改动都直接服务于 #57 的目标。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

1 participant