chore: replace @ts-expect-error with proper type assertions in test callbacks#162
Conversation
WalkthroughThe changes update two test cases by replacing untyped inline arrow functions (used as keys) with explicitly typed arrow functions that are cast to a general function signature. This eliminates the need for TypeScript expect-error comments, improving type safety in the test input definitions. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/__tests__/index.ts (2)
198-204: Nice replacement for@ts-expect-error; suggest a small readability tweakThe explicit assertion is correct and keeps the tests type-safe. To reduce verbosity and duplication across tests, introduce a simple alias and use it in the cast.
Apply this diff within the selected lines:
- { - keys: [ - ((item: {name: {first: string}}) => item.name.first) as ( - item: unknown, - ) => string, - ], - }, + { + keys: [ + ((item: {name: {first: string}}) => item.name.first) as KeyFn, + ], + },Add this near the top of the file (outside the selected lines):
type KeyFn = (item: unknown) => string
626-632: Consistent, type-safe callback; same readability tweak appliesThis cast is correct and aligns with the PR goal. As above, consider a
KeyFnalias to avoid repeating the full function type.Apply this diff within the selected lines:
- { - keys: [ - ((item: {name: string}) => item.name.replace(/_/g, ' ')) as ( - item: unknown, - ) => string, - ], - }, + { + keys: [ + ((item: {name: string}) => item.name.replace(/_/g, ' ')) as KeyFn, + ], + },
|
Thanks! |
|
🎉 This PR is included in version 8.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What: Update test callbacks to use proper TypeScript typing
Why: Remove
@ts-expect-errorsuppressions in favor of proper typesHow: Replace with typed function callbacks and type assertions
Checklist:
Summary by CodeRabbit