-
Notifications
You must be signed in to change notification settings - Fork 11
fix: replace any types with proper TypeScript types in hook templates #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replace `any` with specific types based on Claude Code schema - Use `unknown` for generic record values following TypeScript best practices - Fix Node.js import protocol warning by using 'node:path' - All linting issues resolved, no more Biome warnings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
WalkthroughThe changes focus on improving type safety and clarity in TypeScript code. Type assertions and type annotations are refined across several files, particularly for payloads and function parameters, without altering any logic or control flow. Some import statements are also updated for consistency. Changes
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
templates/hooks/index.ts (1)
22-22: Type assertion improvement looks good, but consider runtime validation.The change from
anyto{file_path: string}improves type safety. However, since this is a runtime type assertion, consider adding a runtime check to ensurefile_pathexists before destructuring.- const {file_path} = payload.tool_input as {file_path: string} + const toolInput = payload.tool_input as {file_path?: string} + if (!toolInput.file_path) return {} + const {file_path} = toolInput
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
templates/hooks/index.ts(1 hunks)templates/hooks/lib.ts(4 hunks)templates/hooks/session.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`templates/**/*`: Hook templates must be stored in the 'templates/' directory and are copied to the user's '.claude/' directory during initialization.
templates/**/*: Hook templates must be stored in the 'templates/' directory and are copied to the user's '.claude/' directory during initialization.
📄 Source: CodeRabbit Inference Engine (CLAUDE.md)
List of files the instruction was applied to:
templates/hooks/index.tstemplates/hooks/session.tstemplates/hooks/lib.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to tsconfig.json : TypeScript strict mode must be enabled.
templates/hooks/index.ts (1)
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
templates/hooks/session.ts (1)
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
🧬 Code Graph Analysis (2)
templates/hooks/session.ts (1)
templates/hooks/lib.ts (1)
saveSessionData(113-136)
templates/hooks/lib.ts (1)
templates/hooks/session.ts (1)
saveSessionData(7-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: test (windows-latest, 20)
- GitHub Check: test (macos-latest, 20)
- GitHub Check: test (windows-latest, 18)
- GitHub Check: test (ubuntu-latest, 20)
- GitHub Check: test (ubuntu-latest, 18)
🔇 Additional comments (8)
templates/hooks/session.ts (2)
3-3: Good improvement to use Node.js protocol import.Using
node:pathis the recommended approach for Node.js built-in modules as it makes the import explicit and avoids potential conflicts with npm packages.
15-15: Improved type annotation for session data array.The explicit type annotation improves type safety and clarity. The type aligns well with the function's logic.
templates/hooks/lib.ts (6)
11-11: Excellent type safety improvement.Changing from
Record<string, any>toRecord<string, unknown>is a significant improvement.unknownis type-safe and requires explicit type checks before use, unlikeanywhich disables type checking.
18-19: Consistent type safety improvements for tool data.Both
tool_inputandtool_responsebenefit from the change toRecord<string, unknown>, maintaining consistency across the payload interfaces.
113-113: More precise parameter typing for saveSessionData.Changing from
anytoHookPayloadprovides proper type safety and ensures the payload has the required structure includingsession_id. This is more accurate than the generic approach.
118-118: Explicit array typing improves code clarity.The explicit type annotation makes the expected structure clear and provides better IntelliSense support.
139-139: Type-safe logging function parameter.Changing from
any[]tounknown[]maintains type safety while still allowing any values to be logged. This is the appropriate choice for a logging utility.
153-153: Precise union type assertion.Using
HookPayload['hook_type']instead ofanyprovides compile-time validation that the hook_type is one of the valid values from the union type. This catches potential runtime errors at compile time.
…on.ts - Import HookPayload type from './lib' - Update saveSessionData function signature to use HookPayload - Update sessionData array type to use HookPayload - This unifies the payload type across both lib.ts and session.ts files
|
🎉 This PR is included in version 1.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
anytypes with proper TypeScript types based on Claude Code schemanode:pathinstead ofpathsession.tsby importing and usingHookPayloadtype from./libChanges
payload.tool_inputto proper type interface instead ofanytool_inputandtool_responsefromRecord<string, any>toRecord<string, unknown>saveSessionDatato acceptHookPayloadtype instead ofanysessionDataarray typing with proper interfacelogfunction parameters fromany[]tounknown[]hook_typecasting to use proper union typepathmodulesaveSessionDataparameter fromRecord<string, unknown>toHookPayloadtypeHookPayloadtype from./libsessionDataarray type to useHookPayloadTest plan
bun run lint- All checks passanywarnings in IDENote: The test failures are pre-existing and occur on the main branch as well. They're related to the test setup not being able to handle TypeScript files when running CLI commands, not to the type fixes in this PR.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Refactor
Chores
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Refactor
Chores