refactor(lint): replace any and tighten type idioms#471
Merged
Conversation
- type table Column._style as CSSProperties - type the cloneElement targets in CDropdownToggle and CCarousel as ReactElement<Record<string, unknown>> instead of ReactElement<any> - type the executeAfterTransition handler argument as Event - simplify isFunction to a typeof check, dropping the Function type and the Object.prototype.toString lookup (fixes ban-types, no-unsafe-function-type, prefer-prototype-methods) - convert the empty Props interface to a type alias (no-empty-object-type) - use replaceAll and Object.hasOwn in table/utils and mergeClassNames - type the CFocusTrap test helper index signature as unknown useForkedRef keeps its variadic dependency list with a scoped disable: the deps cannot be a static array literal and dropping useMemo would reintroduce the ref detach/reattach churn from react/react#13029. The public Item index signature any is left for a dedicated typing decision.
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.
Part of bringing
yarn lintto zero (follow-up to #468/#469/#470). Library type & idiom cleanups — no behavior change.Changes
table/Column._style:any→CSSProperties.CDropdownToggle/CCarouselcloneElementtargets:ReactElement<any>→ReactElement<Record<string, unknown>>.executeAfterTransitionhandler arg:{ target }: { target: any }→{ target }: Event.isFunction: replaced theObject.prototype.toStringlookup with atypeof value === 'function'check and a precise type guard — clearsban-types,no-unsafe-function-type, andprefer-prototype-methodsat once.polymorphicComponent: emptyinterface Props extends AsProp {}→type Props = AsProp(no-empty-object-type).table/utilsreplace(/…/g)→replaceAll;mergeClassNamesobj.hasOwnProperty→Object.hasOwn(both already supported — tsconfig lib is es2023).any→unknown.Deliberately scoped
useForkedRefkeeps its variadicrefsdependency list with a line-scopedreact-hooks/use-memodisable + comment. The rule requires a static array-literal dep list, which a variadic-arity hook cannot provide; droppinguseMemowould reintroduce the ref detach/reattach churn from Share ref with multiple ref handlers react/react#13029. This is a tooling limitation, not a hidden issue.table/Item's[key: string]: … | anyis left as-is. Its values are rendered as React children ({item[colName]}) while the same shape carries object meta-keys (_props/_cellProps); tightening it is a public-API typing decision deferred to its own change.Verification
tsc --noEmitclean,yarn lib:buildsucceeds (validatesreplaceAll/Object.hasOwn).