Skip to content

fix: align shell type definitions across commands#25

Merged
cunoe merged 1 commit intomainfrom
fix/issue-13-shell-type
Mar 31, 2026
Merged

fix: align shell type definitions across commands#25
cunoe merged 1 commit intomainfrom
fix/issue-13-shell-type

Conversation

@cunoe
Copy link
Copy Markdown
Contributor

@cunoe cunoe commented Mar 31, 2026

Closes #13

Summary

  • Expand ShellKind type to include bash, zsh, fish alongside existing sh, cmd, powershell
  • Remove local ShellKind type in export.ts, use shared type from @/types/common
  • Update detectDefaultShell() return type to ShellKind

Copy link
Copy Markdown

@leaperone-bot leaperone-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Code Review 🟢

总结

这是一个简洁且正确的类型对齐修复 PR,解决了 ShellKind 类型定义在多处不一致的问题。改动范围小、风险低,逻辑清晰。

优点

  1. 消除了类型不一致detectDefaultShell() 已经会返回 'bash''zsh''fish',但旧的 ShellKind 类型并不包含这些值,存在运行时与类型定义脱节的问题。此 PR 正确修复了这一点。
  2. 去除了重复定义export.ts 中的本地 ShellKind 类型被移除,改为使用共享类型,符合 DRY 原则。
  3. 返回类型收窄detectDefaultShell() 的返回类型从 string 改为 ShellKind,增强了类型安全性。

小建议(非阻塞)

  1. unsetEnv() 中的冗余类型断言:在 src/utils/env/index.ts 第 217 行,unsetEnv 函数中有 detectDefaultShell() as ShellKind。由于 detectDefaultShell() 现在已经返回 ShellKind,这个 as ShellKind 断言可以移除了。
  2. generateUnsetCommandgenerateExportCommand 的参数类型:这两个函数的 shell 参数仍然是 string 类型。可以考虑后续将其也改为 ShellKind,以进一步增强类型安全,实现完整的类型链路。
  3. export.ts 中的帮助文本和 option 描述仍然写着 sh | cmd | powershell,未包含新增的 bashzshfish。建议更新 --shell option 的描述以反映实际支持的 shell 类型。unset.ts 也有同样的问题。

以上都是后续可以改进的点,不影响本次合并。

@cunoe cunoe merged commit c241016 into main Mar 31, 2026
1 of 2 checks passed
@cunoe cunoe deleted the fix/issue-13-shell-type branch March 31, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell 类型定义不匹配

2 participants