Skip to content

Commit a27cc6c

Browse files
committed
refactor: add reasons why @ts-expect-error is being used
1 parent 37c28b2 commit a27cc6c

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

src/CSSTransition.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,35 +357,35 @@ class CSSTransition extends React.Component<Props> {
357357
}
358358

359359
if (className) {
360-
// @ts-expect-error
360+
// @ts-expect-error FIXME: Property 'active' does not exist on type '{} | {} | {}'.ts(7053)
361361
this.appliedClasses[type][phase] = className;
362-
// @ts-expect-error
362+
// @ts-expect-error FIXME: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.ts(2345)
363363
addClass(node, className);
364364
}
365365
}
366366

367367
removeClasses(node: HTMLElement | null, type: TransitionClassNameKeys) {
368368
const {
369-
// @ts-expect-error
369+
// @ts-expect-error FIXME: Property 'base' does not exist on type '{} | {} | {}'.ts(2339)
370370
base: baseClassName,
371-
// @ts-expect-error
371+
// @ts-expect-error FIXME: Property 'active' does not exist on type '{} | {} | {}'.ts(2339)
372372
active: activeClassName,
373-
// @ts-expect-error
373+
// @ts-expect-error FIMXE: Property 'done' does not exist on type '{} | {} | {}'.ts(2339)
374374
done: doneClassName,
375375
} = this.appliedClasses[type];
376376

377377
this.appliedClasses[type] = {};
378378

379379
if (baseClassName) {
380-
// @ts-expect-error
380+
// @ts-expect-error FIXME: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.ts(2345)
381381
removeClass(node, baseClassName);
382382
}
383383
if (activeClassName) {
384-
// @ts-expect-error
384+
// @ts-expect-error FIXME: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.ts(2345)
385385
removeClass(node, activeClassName);
386386
}
387387
if (doneClassName) {
388-
// @ts-expect-error
388+
// @ts-expect-error FIXME: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.ts(2345)
389389
removeClass(node, doneClassName);
390390
}
391391
}

src/ReplaceTransition.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ class ReplaceTransition extends React.Component<Props> {
5858
originalArgs: any[]
5959
) {
6060
const { children } = this.props;
61-
// @ts-expect-error
61+
// @ts-expect-error FIXME: Type 'string' is not assignable to type 'ReactElement<Props, string | JSXElementConstructor<any>>'.ts(2322)
6262
const child: ReactElement<TransitionProps> =
6363
React.Children.toArray(children)[idx];
6464

65-
// @ts-expect-error
65+
// @ts-expect-error FIXME: A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)
6666
if (child.props[handler]) child.props[handler](...originalArgs);
6767
if (this.props[handler]) {
6868
const maybeNode = child.props.nodeRef
6969
? undefined
7070
: ReactDOM.findDOMNode(this);
71-
// @ts-expect-error
71+
// @ts-expect-error FIXME: Argument of type 'Element | Text | null | undefined' is not assignable to parameter of type 'HTMLElement'.ts(2769)
7272
this.props[handler](maybeNode);
7373
}
7474
}
@@ -85,15 +85,15 @@ class ReplaceTransition extends React.Component<Props> {
8585
onExited: _onExited,
8686
...props
8787
} = this.props;
88-
// @ts-expect-error
88+
// @ts-expect-error FIXME: Target requires 2 element(s) but source may have fewer.ts(2322)
8989
const [first, second]: [
9090
ReactElement<TransitionProps>,
9191
ReactElement<TransitionProps>
9292
] = React.Children.toArray(children);
9393

9494
return (
95+
// @ts-expect-error FIXME: This JSX tag's 'children' prop expects type 'ReactNode[] & ReactNode' which requires multiple children, but only a single child was provided.ts(2745)
9596
<TransitionGroup {...props}>
96-
{/* @ts-expect-error */}
9797
{inProp
9898
? React.cloneElement(first, {
9999
key: 'first',

src/SwitchTransition.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type RenderCallbackParameter = {
4444

4545
const leaveRenders = {
4646
[modes.out]: ({ current, changeState }: RenderCallbackParameter) =>
47-
// @ts-expect-error FIXME
47+
// @ts-expect-error FIXME: Type 'null' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.ts(2769)
4848
React.cloneElement(current, {
4949
in: false,
50-
// @ts-expect-error FIXME
50+
// @ts-expect-error FIXME: Type 'null' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.ts(2345)
5151
onExited: callHook(current, 'onExited', () => {
5252
changeState(ENTERING, null);
5353
}),
@@ -72,10 +72,10 @@ const enterRenders = {
7272
}),
7373
}),
7474
[modes.in]: ({ current, children, changeState }: RenderCallbackParameter) => [
75-
// @ts-expect-error FIXME
75+
// @ts-expect-error FIXME: Type 'null' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.ts(2769)
7676
React.cloneElement(current, {
7777
in: false,
78-
// @ts-expect-error FIXME
78+
// @ts-expect-error FIXME: Type 'null' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.ts(2345)
7979
onExited: callHook(current, 'onExited', () => {
8080
changeState(ENTERED, React.cloneElement(children, { in: true }));
8181
}),

src/Transition.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,19 @@ class Transition extends React.Component<Props, State> {
175175
* [test/CSSTransition-test.js](https://github.com/reactjs/react-transition-group/blob/13435f897b3ab71f6e19d724f145596f5910581c/test/CSSTransition-test.js#L362-L437)).
176176
*/
177177
nodeRef: PropTypes.shape({
178-
// @ts-expect-error
178+
// @ts-expect-error We'll remove the PropTypes definition
179179
current:
180180
typeof Element === 'undefined'
181181
? PropTypes.any
182-
: // @ts-expect-error
182+
: // @ts-expect-error We'll remove the PropTypes definition
183183
(propValue, key, componentName, location, propFullName, secret) => {
184184
const value = propValue[key];
185185

186186
return PropTypes.instanceOf(
187187
value && 'ownerDocument' in value
188188
? value.ownerDocument.defaultView.Element
189189
: Element
190-
// @ts-expect-error
190+
// @ts-expect-error We'll remove the PropTypes definition
191191
)(propValue, key, componentName, location, propFullName, secret);
192192
},
193193
}),
@@ -281,9 +281,9 @@ class Transition extends React.Component<Props, State> {
281281
*/
282282
timeout: (props: any, ...args: any[]) => {
283283
let pt = timeoutsShape;
284-
// @ts-expect-error
284+
// @ts-expect-error We'll remove the PropTypes definition
285285
if (!props.addEndListener) pt = pt.isRequired;
286-
// @ts-expect-error
286+
// @ts-expect-error We'll remove the PropTypes definition
287287
return pt(props, ...args);
288288
},
289289

@@ -633,7 +633,7 @@ class Transition extends React.Component<Props, State> {
633633
<TransitionGroupContext.Provider value={null}>
634634
{typeof children === 'function'
635635
? children(status, childProps)
636-
: // @ts-expect-error FIXME
636+
: // @ts-expect-error FIXME: Type 'ReactChildren' is missing the following properties from type 'ReactElement<any, string | JSXElementConstructor<any>>': type, props, keyts(2769)
637637
React.cloneElement(React.Children.only(children), childProps)}
638638
</TransitionGroupContext.Provider>
639639
);

src/TransitionGroup.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types';
2-
import React from 'react';
3-
import type { ReactElement, ReactChildren } from 'react';
2+
import React, { ReactNode } from 'react';
3+
import type { ReactElement } from 'react';
44
import TransitionGroupContext from './TransitionGroupContext';
55

66
import {
@@ -20,15 +20,15 @@ const defaultProps = {
2020

2121
type Props = {
2222
component: any;
23-
children: ReactChildren;
23+
children: ReactNode[];
2424
appear: boolean;
2525
enter: boolean;
2626
exit: boolean;
2727
childFactory: (child: ReactElement) => ReactElement;
2828
};
2929

3030
type State = {
31-
children: ReactChildren;
31+
children: ReactNode[];
3232
contextValue: { isMounting: boolean };
3333
handleExited: (
3434
child: ReactElement<{ onExited: (node: HTMLElement) => void }>,
@@ -117,7 +117,7 @@ class TransitionGroup extends React.Component<Props, State> {
117117
const handleExited = this.handleExited.bind(this);
118118

119119
// Initial children should all be entering, dependent on appear
120-
// @ts-expect-error
120+
// @ts-expect-error FIXME: Property 'children' is missing in type '{ contextValue: { isMounting: true; }; handleExited: (child: React.ReactElement<{ onExited: (node: HTMLElement) => void; }, string | React.JSXElementConstructor<any>>, node: HTMLElement) => void; firstRender: true; }' but required in type 'Readonly<State>'.ts(2741)
121121
this.state = {
122122
contextValue: { isMounting: true },
123123
handleExited,
@@ -154,8 +154,7 @@ class TransitionGroup extends React.Component<Props, State> {
154154
node: HTMLElement
155155
) {
156156
let currentChildMapping = getChildMapping(this.props.children);
157-
// @ts-expect-error
158-
if (child.key in currentChildMapping) return;
157+
if (child.key && child.key in currentChildMapping) return;
159158

160159
if (child.props.onExited) {
161160
child.props.onExited(node);
@@ -164,8 +163,10 @@ class TransitionGroup extends React.Component<Props, State> {
164163
if (this.mounted) {
165164
this.setState((state) => {
166165
let children = { ...state.children };
167-
// @ts-expect-error
168-
delete children[child.key];
166+
if (child.key) {
167+
// @ts-expect-error FIXME: Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015)
168+
delete children[child.key];
169+
}
169170
return { children };
170171
});
171172
}
@@ -174,6 +175,7 @@ class TransitionGroup extends React.Component<Props, State> {
174175
render() {
175176
const { component: Component, childFactory, ...props } = this.props;
176177
const { contextValue } = this.state;
178+
// @ts-expect-error FIXME: Type 'undefined' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>'.ts(2345)
177179
const children = values(this.state.children).map(childFactory);
178180
const {
179181
appear: _appear,

src/utils/ChildMapping.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Children, cloneElement, isValidElement } from 'react';
2-
import type { ReactChild, ReactChildren, ReactElement, ReactNode } from 'react';
2+
import type { ReactChild, ReactElement, ReactNode } from 'react';
33

44
/**
55
* Given `this.props.children`, return an object mapping key to child.
@@ -8,17 +8,18 @@ import type { ReactChild, ReactChildren, ReactElement, ReactNode } from 'react';
88
* @return {object} Mapping of key to child
99
*/
1010
export function getChildMapping(
11-
children: ReactChildren,
11+
children: ReactNode[] | ReactNode,
1212
mapFn?: (child: ReactElement) => ReactElement
1313
) {
1414
let mapper = (child: ReactNode) =>
1515
mapFn && isValidElement(child) ? mapFn(child) : child;
1616

1717
let result = Object.create(null);
1818
if (children)
19+
// @ts-expect-error FIXME: Object is possibly 'null' or 'undefined'.ts(2533)
1920
Children.map(children, (c) => c).forEach((child) => {
2021
// run the map function here instead so that the key is the computed one
21-
// @ts-expect-error: Property 'key' does not exist on type 'ReactChildren'
22+
// @ts-expect-error FIXME: Property 'key' does not exist on type 'string'.ts(2339)
2223
result[child.key] = mapper(child);
2324
});
2425
return result;
@@ -98,7 +99,7 @@ function getProp(
9899
}
99100

100101
export function getInitialChildMapping(
101-
props: { children: ReactChildren },
102+
props: { children: ReactNode[] },
102103
onExited: (child: ReactChild) => void
103104
) {
104105
return getChildMapping(props.children, (child: ReactElement) => {
@@ -113,7 +114,7 @@ export function getInitialChildMapping(
113114
}
114115

115116
export function getNextChildMapping(
116-
nextProps: { children: ReactChildren },
117+
nextProps: { children: ReactNode[] },
117118
prevChildMapping: Record<string, ReactChild>,
118119
onExited: (child: ReactChild) => void
119120
) {

0 commit comments

Comments
 (0)