fix: align shell type definitions across commands#25
Merged
Conversation
leaperone-bot
approved these changes
Mar 31, 2026
leaperone-bot
left a comment
There was a problem hiding this comment.
🤖 Code Review 🟢
总结
这是一个简洁且正确的类型对齐修复 PR,解决了 ShellKind 类型定义在多处不一致的问题。改动范围小、风险低,逻辑清晰。
优点
- 消除了类型不一致:
detectDefaultShell()已经会返回'bash'、'zsh'、'fish',但旧的ShellKind类型并不包含这些值,存在运行时与类型定义脱节的问题。此 PR 正确修复了这一点。 - 去除了重复定义:
export.ts中的本地ShellKind类型被移除,改为使用共享类型,符合 DRY 原则。 - 返回类型收窄:
detectDefaultShell()的返回类型从string改为ShellKind,增强了类型安全性。
小建议(非阻塞)
unsetEnv()中的冗余类型断言:在src/utils/env/index.ts第 217 行,unsetEnv函数中有detectDefaultShell() as ShellKind。由于detectDefaultShell()现在已经返回ShellKind,这个as ShellKind断言可以移除了。generateUnsetCommand和generateExportCommand的参数类型:这两个函数的shell参数仍然是string类型。可以考虑后续将其也改为ShellKind,以进一步增强类型安全,实现完整的类型链路。export.ts中的帮助文本和 option 描述仍然写着sh | cmd | powershell,未包含新增的bash、zsh、fish。建议更新--shelloption 的描述以反映实际支持的 shell 类型。unset.ts也有同样的问题。
以上都是后续可以改进的点,不影响本次合并。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13
Summary
ShellKindtype to includebash,zsh,fishalongside existingsh,cmd,powershellShellKindtype inexport.ts, use shared type from@/types/commondetectDefaultShell()return type toShellKind