-
Notifications
You must be signed in to change notification settings - Fork 4k
avoid using as any assertion where not required
#578
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
base: main
Are you sure you want to change the base?
Conversation
👷 Deploy request for appcut pending review.Visit the deploys page to approve it
|
|
@GameRoMan is attempting to deploy a commit to the OpenCut OSS Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughRefactors bindAction in apps/web/src/constants/actions.ts to always initialize boundActions[action] as an array when undefined and then push the handler, removing conditional branching and inline type casts. No exported signatures change. updateActiveActions behavior is unchanged. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ 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/Issue comments)Type 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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
apps/web/src/constants/actions.ts (4)
151-157: Remove remainingas anyand prefer for...of over forEach.This keeps the invocation fully typed and aligns with our guidelines.
export const invokeAction: InvokeActionFunc = <A extends Action>( action: A, args?: ArgOfHoppAction<A>, trigger?: InvocationTriggers ) => { - boundActions[action]?.forEach((handler) => (handler as any)(args, trigger)); + const handlers = boundActions[action] as Array<ActionFunc<A>> | undefined; + if (!handlers) return; + for (const handler of handlers) { + handler(args as ArgOfHoppAction<A>, trigger); + } };
163-173: Type-safe unbind withoutas any; keep updateActiveActions behavior.Avoids
anyand optional chaining on mutation; logic unchanged.export function unbindAction<A extends Action>( action: A, handler: ActionFunc<A> ) { - // 'any' assertion because TypeScript doesn't seem to be able to figure out the links. - boundActions[action] = boundActions[action]?.filter( - (x) => x !== handler - ) as any; - - if (boundActions[action]?.length === 0) { - delete boundActions[action]; - } + const list = boundActions[action]; + if (list) { + const next = list.filter((x): x is ActionFunc<A> => x !== handler); + if (next.length > 0) { + boundActions[action] = next; + } else { + delete boundActions[action]; + } + } updateActiveActions(); }
206-211: Eliminateanyin stableHandler; keep types via Parameters<>.This keeps the wrapper fully typed and generic-safe.
- const stableHandler = useCallback( - (args: any, trigger?: InvocationTriggers) => { - (handlerRef.current as any)(args, trigger); - }, - [] - ) as ActionFunc<A>; + const stableHandler = useCallback( + ((...params: Parameters<ActionFunc<A>>) => { + (handlerRef.current as ActionFunc<A>)(...params); + }) as ActionFunc<A>, + [] + );
151-157: Remove all remainingas anycasts in apps/web/src/constants/actions.tsThe following casts were found and must be replaced with properly typed handlers:
- Line 156:
(handler as any)(args, trigger)- Line 166:
) as any;- Line 208:
(handlerRef.current as any)(args, trigger)Ensure each handler is typed (e.g. via
InvokeActionFuncandArgOfHoppAction<A>) so theseas anycasts can be eliminated.
🧹 Nitpick comments (3)
apps/web/src/constants/actions.ts (3)
124-129: Good removal of unnecessary branching; initialize-then-push is clean.This achieves the PR goal for bindAction without using
as any. Consider the nullish assignment idiom for brevity:
const list = (boundActions[action] ??= []); list.push(handler);
5-11: Useimport typefor type-only import (MutableRefObject).Matches our TS import style guideline.
-import { - useEffect, - useRef, - useState, - useCallback, - MutableRefObject, -} from "react"; +import { useEffect, useRef, useState, useCallback } from "react"; +import type { MutableRefObject } from "react";
24-26: Prefer for...of over Array.forEach in emitter.Small perf/readability win and aligns with our style guide.
- emit(actions: Action[]) { - this.listeners.forEach((listener) => listener(actions)); - } + emit(actions: Action[]) { + for (const listener of this.listeners) { + listener(actions); + } + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/web/src/constants/actions.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use TypeScript namespaces.
Don't use non-null assertions with the!postfix operator.
Don't use parameter properties in class constructors.
Don't use user-defined types.
Useas constinstead of literal types and type annotations.
Use eitherT[]orArray<T>consistently.
Initialize each enum member value explicitly.
Useexport typefor types.
Useimport typefor types.
Make sure all enum members are literal values.
Don't use TypeScript const enum.
Don't declare empty interfaces.
Don't let variables evolve into any type through reassignments.
Don't use the any type.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use implicit any type on variable declarations.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use the TypeScript directive @ts-ignore.
Use consistent accessibility modifiers on class properties and methods.
Use function types instead of object types with call signatures.
Don't use void type outside of generic or return types.
**/*.{ts,tsx}: Don't use primitive type aliases or misleading types
Don't use the TypeScript directive @ts-ignore
Don't use TypeScript enums
Use either T[] or Array consistently
Don't use the any type
Files:
apps/web/src/constants/actions.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{js,jsx,ts,tsx}: Don't use the return value of React.render.
Don't use consecutive spaces in regular expression literals.
Don't use theargumentsobject.
Don't use primitive type aliases or misleading types.
Don't use the comma operator.
Don't write functions that exceed a given Cognitive Complexity score.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use uselessthisaliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names that aren't base 10 or use underscore separators.
Remove redundant terms from logical expressions.
Use while loops instead of...
Files:
apps/web/src/constants/actions.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{ts,tsx,js,jsx}: Don't use the comma operator
Use for...of statements instead of Array.forEach
Don't initialize variables to undefined
Use .flatMap() instead of map().flat() when possible
Don't assign a value to itself
Avoid unused imports and variables
Don't use await inside loops
Don't hardcode sensitive data like API keys and tokens
Don't use the delete operator
Don't use global eval()
Use String.slice() instead of String.substr() and String.substring()
Don't use else blocks when the if block breaks early
Put default function parameters and optional function parameters last
Use new when throwing an error
Use String.trimStart() and String.trimEnd() over String.trimLeft() and String.trimRight()
Files:
apps/web/src/constants/actions.ts
⏰ 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). (1)
- GitHub Check: Vade Review
Summary by CodeRabbit