Fix type#1239
Conversation
📝 WalkthroughWalkthroughThis PR replaces 120+ auto-generated type stubs across the codebase with concrete TypeScript type definitions, covering built-in tool names, SDK hook contracts, UI state machines, data schemas, and utility types. No runtime behavior changes; purely type-system improvements. ChangesType Stub Replacement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
src/components/agents/new-agent-creation/types.ts (1)
3-3: ⚡ Quick winUse
src/*alias for internal import.Please switch the
SettingSourceimport to the configuredsrc/*alias instead of a deep relative path.Suggested diff
-import type { SettingSource } from '../../../utils/settings/constants.js' +import type { SettingSource } from 'src/utils/settings/constants.js'As per coding guidelines, Use
src/*path alias for imports as configured in tsconfig; valid imports likeimport { ... } from 'src/utils/...'are preferred.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/agents/new-agent-creation/types.ts` at line 3, Replace the deep relative import of SettingSource with the project path-alias import: update the import that currently references '../../../utils/settings/constants.js' to use the tsconfig alias (e.g. import type { SettingSource } from 'src/utils/settings/constants'), removing the deep-relative traversal and the .js extension so TypeScript path-mapping resolves correctly for the SettingSource type used in this module.src/commands/plugin/ManagePlugins.tsx (1)
1257-1257: ⚡ Quick winAvoid scope casts; use a type guard to narrow
UnifiedInstalledScopeinsteadLines 1257 and 1583–1585 cast
pluginScopeto satisfyisInstallableScopeanduninstallPluginOp. These casts are unnecessary because the unions are already compatible with the expected input types after the precedingisBuiltincheck. The same function is called without casts at lines 1097 and 1685, revealing the casts are inconsistent. A local type guard narrowsUnifiedInstalledScopeproperly and maintains type safety.Suggested change
+const isInstallableUnifiedScope = (scope: UnifiedInstalledScope): scope is InstallableScope => + scope === 'user' || scope === 'project' || scope === 'local'; - if (isBuiltin || isInstallableScope(pluginScope as PersistablePluginScope)) { + if (isBuiltin || isInstallableUnifiedScope(pluginScope)) { - const result = isInstallableScope(pluginScope as PersistablePluginScope) - ? await uninstallPluginOp(pluginId, pluginScope as InstallableScope, false) + const result = isInstallableUnifiedScope(pluginScope) + ? await uninstallPluginOp(pluginId, pluginScope, false) : await uninstallPluginOp(pluginId, 'user', false);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/plugin/ManagePlugins.tsx` at line 1257, Replace the unsafe casts of pluginScope to PersistablePluginScope by adding and using a local type guard that narrows UnifiedInstalledScope (e.g., function isPersistableScope(s: UnifiedInstalledScope): s is PersistablePluginScope) and use that guard wherever isInstallableScope and uninstallPluginOp are called (locations referencing isBuiltin, isInstallableScope, uninstallPluginOp and pluginScope) instead of casting; this keeps type safety consistent with the other call sites that already omit casts and removes the redundant explicit type assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/wizard/types.ts`:
- Around line 1-4: The type alias WizardStepComponent currently references
React.ComponentType without importing React; update the imports to pull
ComponentType directly (e.g., import type { Dispatch, ReactNode, SetStateAction,
ComponentType } from 'react') and change the union to use ComponentType (i.e.,
WizardStepComponent = (() => ReactNode) | ComponentType) so strict TypeScript
checking passes; ensure you only add the type import and adjust the type
reference in types.ts.
In `@src/components/wizard/WizardProvider.tsx`:
- Line 126: The component renders a fallback with a logical OR which treats
valid falsy React nodes (like 0, '', false) as absent; in WizardProvider replace
the fallback expression using children || <CurrentStepComponent /> with a
nullish coalescing fallback so only null/undefined trigger the fallback (use
children ?? <CurrentStepComponent />) when rendering inside the WizardProvider
component where children and CurrentStepComponent are used.
In `@src/entrypoints/sdk/coreTypes.generated.ts`:
- Around line 121-252: HookInput was changed to use SessionEnd.reason and
FileChanged.file_path but the public alias types still expect exit_reason and
path, causing conflicting SDK types; update the exported alias contracts to
accept the new keys (or provide backward-compatible unions) by replacing
references to exit_reason and path in the alias definitions with reason and
file_path (or define types that include both keys), and update any alias type
names that map to HookInput (referencing HookInput, SessionEnd, FileChanged and
the public alias types where exit_reason and path are defined) so the SDK
surface types align.
---
Nitpick comments:
In `@src/commands/plugin/ManagePlugins.tsx`:
- Line 1257: Replace the unsafe casts of pluginScope to PersistablePluginScope
by adding and using a local type guard that narrows UnifiedInstalledScope (e.g.,
function isPersistableScope(s: UnifiedInstalledScope): s is
PersistablePluginScope) and use that guard wherever isInstallableScope and
uninstallPluginOp are called (locations referencing isBuiltin,
isInstallableScope, uninstallPluginOp and pluginScope) instead of casting; this
keeps type safety consistent with the other call sites that already omit casts
and removes the redundant explicit type assertions.
In `@src/components/agents/new-agent-creation/types.ts`:
- Line 3: Replace the deep relative import of SettingSource with the project
path-alias import: update the import that currently references
'../../../utils/settings/constants.js' to use the tsconfig alias (e.g. import
type { SettingSource } from 'src/utils/settings/constants'), removing the
deep-relative traversal and the .js extension so TypeScript path-mapping
resolves correctly for the SettingSource type used in this module.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 89acc4cf-7261-447a-8a0b-cdcad8e5b2ba
📒 Files selected for processing (68)
packages/@ant/ink/src/core/cursor.tspackages/@ant/ink/src/core/events/paste-event.tspackages/@ant/ink/src/core/events/resize-event.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/BashTool/toolName.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/ExitPlanModeTool/constants.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/FileEditTool/constants.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/FileReadTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/FileWriteTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/GlobTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/GrepTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/NotebookEditTool/constants.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/SendMessageTool/constants.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/WebFetchTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/tools/WebSearchTool/prompt.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/utils/auth.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/utils/embeddedTools.tspackages/builtin-tools/src/tools/AgentTool/built-in/src/utils/settings/settings.tspackages/builtin-tools/src/tools/AgentTool/src/Tool.tspackages/builtin-tools/src/tools/AgentTool/src/components/ConfigurableShortcutHint.tspackages/builtin-tools/src/tools/AgentTool/src/components/CtrlOToExpand.tspackages/builtin-tools/src/tools/AgentTool/src/components/design-system/Byline.tspackages/builtin-tools/src/tools/AgentTool/src/components/design-system/KeyboardShortcutHint.tspackages/builtin-tools/src/tools/AgentTool/src/types/message.tspackages/builtin-tools/src/tools/AgentTool/src/utils/debug.tspackages/builtin-tools/src/tools/AgentTool/src/utils/promptCategory.tspackages/builtin-tools/src/tools/AgentTool/src/utils/settings/constants.tspackages/builtin-tools/src/tools/AskUserQuestionTool/src/bootstrap/state.tspackages/builtin-tools/src/tools/AskUserQuestionTool/src/components/MessageResponse.tspackages/builtin-tools/src/tools/AskUserQuestionTool/src/constants/figures.tspackages/builtin-tools/src/tools/AskUserQuestionTool/src/utils/permissions/PermissionMode.tspackages/builtin-tools/src/tools/BashTool/src/Tool.tspackages/builtin-tools/src/tools/BashTool/src/bootstrap/state.tspackages/builtin-tools/src/tools/BashTool/src/hooks/useCanUseTool.tspackages/builtin-tools/src/tools/BashTool/src/services/analytics/growthbook.tspackages/builtin-tools/src/tools/BashTool/src/services/analytics/index.tspackages/builtin-tools/src/tools/BashTool/src/state/AppState.tspackages/builtin-tools/src/tools/BashTool/src/utils/Shell.tspackages/builtin-tools/src/tools/BashTool/src/utils/cwd.tspackages/builtin-tools/src/tools/BashTool/src/utils/permissions/filesystem.tspackages/builtin-tools/src/tools/BashTool/src/utils/sandbox/sandbox-ui-utils.tspackages/builtin-tools/src/tools/ExecuteTool/__tests__/ExecuteTool.test.tspackages/builtin-tools/src/tools/NotebookEditTool/NotebookEditTool.tssrc/cli/transports/Transport.tssrc/commands/login/getAuthStatus.tssrc/commands/plugin/ManagePlugins.tsxsrc/commands/plugin/types.tssrc/commands/plugin/unifiedTypes.tssrc/components/FeedbackSurvey/utils.tssrc/components/Spinner/types.tssrc/components/StatusLine.tsxsrc/components/agents/new-agent-creation/types.tssrc/components/mcp/types.tssrc/components/ui/option.tssrc/components/wizard/WizardProvider.tsxsrc/components/wizard/types.tssrc/constants/querySource.tssrc/entrypoints/agentSdkTypes.tssrc/entrypoints/sdk/coreTypes.generated.tssrc/services/lsp/types.tssrc/services/tips/tipRegistry.tssrc/services/tips/types.tssrc/types/fileSuggestion.tssrc/types/notebook.tssrc/types/statusLine.tssrc/utils/__tests__/notebook.test.tssrc/utils/hooks.tssrc/utils/notebook.tssrc/utils/plugins/mcpbHandler.ts
| import type { Dispatch, ReactNode, SetStateAction } from 'react' | ||
|
|
||
| /** 向导中每一步的组件(无 props 或由 Wizard 包裹后注入上下文)。 */ | ||
| export type WizardStepComponent = (() => ReactNode) | React.ComponentType |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Inspect TS config flags relevant to UMD global namespace access:"
for f in $(fd -i '^tsconfig(\..*)?\.json$'); do
echo "== $f =="
rg -n '"(strict|allowUmdGlobalAccess|jsx|types)"' "$f" || true
done
echo
echo "Confirm current usage in wizard types:"
rg -n 'React\.ComponentType|WizardStepComponent' src/components/wizard/types.tsRepository: claude-code-best/claude-code
Length of output: 1553
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Full content of src/components/wizard/types.ts ==="
cat -n src/components/wizard/types.ts
echo ""
echo "=== Run type-checking on the file ==="
bunx tsc --noEmit src/components/wizard/types.ts 2>&1 || echo "tsc returned: $?"
echo ""
echo "=== Check if bundler/tsc resolves React.ComponentType ==="
bunx tsc --noEmit 2>&1 | head -20 || trueRepository: claude-code-best/claude-code
Length of output: 1493
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Search for other uses of React.ComponentType in the codebase ==="
rg 'React\.ComponentType|React\.FC|React\.ReactNode' -t ts -t tsx --context=2
echo ""
echo "=== Check for React namespace imports to understand pattern ==="
rg 'import\s+React\s+from|import\s+type\s+\*\s+as\s+React' -t ts -t tsx | head -20
echo ""
echo "=== Check if there are any global React declarations ==="
fd -e d.ts | xargs grep -l 'declare.*React' 2>/dev/null || echo "No global React declarations found"Repository: claude-code-best/claude-code
Length of output: 187
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Search for React.ComponentType usages ==="
rg 'React\.ComponentType' --context=2
echo ""
echo "=== Search for React namespace imports ==="
rg 'import.*React\s+from' --context=1 | head -30
echo ""
echo "=== Check if ComponentType is imported directly elsewhere ==="
rg 'import.*ComponentType' | head -20Repository: claude-code-best/claude-code
Length of output: 3075
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Check PermissionRequest.tsx for React import ==="
head -20 src/components/permissions/PermissionRequest.tsx | cat -n
echo ""
echo "=== Check launchCommand.ts for React import ==="
head -20 src/commands/_shared/launchCommand.ts | cat -n
echo ""
echo "=== Check the specific line in PermissionRequest.tsx where React.ComponentType is used ==="
rg -B 10 'React\.ComponentType<PermissionRequestProps>' src/components/permissions/PermissionRequest.tsx | head -20Repository: claude-code-best/claude-code
Length of output: 3654
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Check launchCommand.ts for React import (full imports section) ==="
head -50 src/commands/_shared/launchCommand.ts | grep -E "^import|^export" | cat -n
echo ""
echo "=== Verify: does src/components/wizard/types.ts actually have React imported? ==="
head -10 src/components/wizard/types.ts | cat -n
echo ""
echo "=== Check for any type declarations or d.ts files that might provide global React ==="
fd -e d.ts -e d.ts.map | xargs grep -l 'declare.*React' 2>/dev/null || echo "No global React type declarations"Repository: claude-code-best/claude-code
Length of output: 1009
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Check the global.d.ts file ==="
cat -n src/types/global.d.ts
echo ""
echo "=== Also check tsconfig to see if global.d.ts is included ==="
rg -A 5 -B 5 'include|typeRoots|types' tsconfig.json tsconfig.base.json 2>/dev/null | head -40Repository: claude-code-best/claude-code
Length of output: 5513
Import ComponentType directly to resolve the strict type-checking error.
Line 4 references React.ComponentType without importing the React namespace. In strict TypeScript mode, this fails type-checking. The jsx transform (react-jsx) doesn't make the React namespace globally available for type annotations.
-import type { Dispatch, ReactNode, SetStateAction } from 'react'
+import type { ComponentType, Dispatch, ReactNode, SetStateAction } from 'react'
@@
-export type WizardStepComponent = (() => ReactNode) | React.ComponentType
+export type WizardStepComponent = (() => ReactNode) | ComponentType🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/wizard/types.ts` around lines 1 - 4, The type alias
WizardStepComponent currently references React.ComponentType without importing
React; update the imports to pull ComponentType directly (e.g., import type {
Dispatch, ReactNode, SetStateAction, ComponentType } from 'react') and change
the union to use ComponentType (i.e., WizardStepComponent = (() => ReactNode) |
ComponentType) so strict TypeScript checking passes; ensure you only add the
type import and adjust the type reference in types.ts.
| return <WizardContext.Provider value={contextValue}>{children || <CurrentStepComponent />}</WizardContext.Provider>; | ||
| return ( | ||
| <WizardContext.Provider value={contextValue as unknown as WizardContextValue<Record<string, unknown>>}> | ||
| {children || <CurrentStepComponent />} |
There was a problem hiding this comment.
Use nullish fallback for children rendering.
Line 126 uses children || <CurrentStepComponent />, which treats valid falsy nodes (0, '', false) as missing. Use ?? so fallback only happens for null/undefined.
Suggested fix
- {children || <CurrentStepComponent />}
+ {children ?? <CurrentStepComponent />}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {children || <CurrentStepComponent />} | |
| {children ?? <CurrentStepComponent />} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/wizard/WizardProvider.tsx` at line 126, The component renders
a fallback with a logical OR which treats valid falsy React nodes (like 0, '',
false) as absent; in WizardProvider replace the fallback expression using
children || <CurrentStepComponent /> with a nullish coalescing fallback so only
null/undefined trigger the fallback (use children ?? <CurrentStepComponent />)
when rendering inside the WizardProvider component where children and
CurrentStepComponent are used.
| | (HookInputBase & { hook_event_name: 'UserPromptSubmit'; prompt: string }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'SessionStart' | ||
| source: 'startup' | 'resume' | 'clear' | 'compact' | ||
| agent_type?: string | ||
| model?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'SessionEnd' | ||
| reason: | ||
| | 'clear' | ||
| | 'resume' | ||
| | 'logout' | ||
| | 'prompt_input_exit' | ||
| | 'other' | ||
| | 'bypass_permissions_disabled' | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'Setup' | ||
| trigger: 'init' | 'maintenance' | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'Stop' | ||
| stop_hook_active: boolean | ||
| last_assistant_message?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'StopFailure' | ||
| error: string | ||
| error_details?: unknown | ||
| last_assistant_message?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'SubagentStart' | ||
| agent_id: string | ||
| agent_type: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'SubagentStop' | ||
| stop_hook_active: boolean | ||
| agent_id: string | ||
| agent_transcript_path: string | ||
| agent_type: string | ||
| last_assistant_message?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'PreCompact' | ||
| trigger: 'manual' | 'auto' | ||
| custom_instructions: string | null | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'PostCompact' | ||
| trigger: 'manual' | 'auto' | ||
| compact_summary: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'TeammateIdle' | ||
| teammate_name: string | ||
| team_name: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'TaskCreated' | ||
| task_id: string | ||
| task_subject: string | ||
| task_description?: string | ||
| teammate_name?: string | ||
| team_name?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'TaskCompleted' | ||
| task_id: string | ||
| task_subject: string | ||
| task_description?: string | ||
| teammate_name?: string | ||
| team_name?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'Elicitation' | ||
| mcp_server_name: string | ||
| message: string | ||
| mode?: 'form' | 'url' | ||
| url?: string | ||
| elicitation_id?: string | ||
| requested_schema?: Record<string, unknown> | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'ElicitationResult' | ||
| mcp_server_name: string | ||
| elicitation_id?: string | ||
| mode?: 'form' | 'url' | ||
| action: 'accept' | 'decline' | 'cancel' | ||
| content?: Record<string, unknown> | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'ConfigChange' | ||
| source: | ||
| | 'user_settings' | ||
| | 'project_settings' | ||
| | 'local_settings' | ||
| | 'policy_settings' | ||
| | 'skills' | ||
| file_path?: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'InstructionsLoaded' | ||
| file_path: string | ||
| memory_type: 'User' | 'Project' | 'Local' | 'Managed' | ||
| load_reason: | ||
| | 'session_start' | ||
| | 'nested_traversal' | ||
| | 'path_glob_match' | ||
| | 'include' | ||
| | 'compact' | ||
| globs?: string[] | ||
| trigger_file_path?: string | ||
| parent_file_path?: string | ||
| }) | ||
| | (HookInputBase & { hook_event_name: 'WorktreeCreate'; name: string }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'WorktreeRemove' | ||
| worktree_path: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'CwdChanged' | ||
| old_cwd: string | ||
| new_cwd: string | ||
| }) | ||
| | (HookInputBase & { | ||
| hook_event_name: 'FileChanged' | ||
| file_path: string | ||
| event: 'change' | 'add' | 'unlink' | ||
| }) |
There was a problem hiding this comment.
Align new hook payload keys with exported alias contracts.
HookInput now uses SessionEnd.reason and FileChanged.file_path, but public aliases still require exit_reason (Line 330) and path (Line 346). This creates conflicting SDK surface types.
Proposed fix
-export type SessionEndHookInput = HookInput & { exit_reason: string }
+export type SessionEndHookInput = Extract<
+ HookInput,
+ { hook_event_name: 'SessionEnd' }
+>
-export type FileChangedHookInput = HookInput & { path: string }
+export type FileChangedHookInput = Extract<
+ HookInput,
+ { hook_event_name: 'FileChanged' }
+>🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/entrypoints/sdk/coreTypes.generated.ts` around lines 121 - 252, HookInput
was changed to use SessionEnd.reason and FileChanged.file_path but the public
alias types still expect exit_reason and path, causing conflicting SDK types;
update the exported alias contracts to accept the new keys (or provide
backward-compatible unions) by replacing references to exit_reason and path in
the alias definitions with reason and file_path (or define types that include
both keys), and update any alias type names that map to HookInput (referencing
HookInput, SessionEnd, FileChanged and the public alias types where exit_reason
and path are defined) so the SDK surface types align.
修复CI不通过的问题。因为少提交了一个ts文件。
Summary by CodeRabbit