1
1
import PropTypes from 'prop-types' ;
2
2
import React from 'react' ;
3
+ import type { ReactElement } from 'react' ;
3
4
import ReactDOM from 'react-dom' ;
4
5
import TransitionGroup from './TransitionGroup' ;
6
+ import type { Props as TransitionProps } from './Transition' ;
7
+
8
+ type Props = Omit < TransitionProps , 'children' > & {
9
+ children : [ ReactElement < TransitionProps > , ReactElement < TransitionProps > ] ;
10
+ } ;
5
11
6
12
/**
7
13
* The `<ReplaceTransition>` component is a specialized `Transition` component
@@ -14,32 +20,35 @@ import TransitionGroup from './TransitionGroup';
14
20
* </ReplaceTransition>
15
21
* ```
16
22
*/
17
- class ReplaceTransition extends React . Component {
18
- handleEnter = ( ...args ) => this . handleLifecycle ( 'onEnter' , 0 , args ) ;
19
- handleEntering = ( ...args ) => this . handleLifecycle ( 'onEntering' , 0 , args ) ;
20
- handleEntered = ( ...args ) => this . handleLifecycle ( 'onEntered' , 0 , args ) ;
23
+ class ReplaceTransition extends React . Component < Props > {
24
+ handleEnter = ( ...args : any ) => this . handleLifecycle ( 'onEnter' , 0 , args ) ;
25
+ handleEntering = ( ...args : any ) =>
26
+ this . handleLifecycle ( 'onEntering' , 0 , args ) ;
27
+ handleEntered = ( ...args : any ) => this . handleLifecycle ( 'onEntered' , 0 , args ) ;
21
28
22
- handleExit = ( ...args ) => this . handleLifecycle ( 'onExit' , 1 , args ) ;
23
- handleExiting = ( ...args ) => this . handleLifecycle ( 'onExiting' , 1 , args ) ;
24
- handleExited = ( ...args ) => this . handleLifecycle ( 'onExited' , 1 , args ) ;
29
+ handleExit = ( ...args : any ) => this . handleLifecycle ( 'onExit' , 1 , args ) ;
30
+ handleExiting = ( ...args : any ) => this . handleLifecycle ( 'onExiting' , 1 , args ) ;
31
+ handleExited = ( ...args : any ) => this . handleLifecycle ( 'onExited' , 1 , args ) ;
25
32
26
- handleLifecycle ( handler , idx , originalArgs ) {
33
+ handleLifecycle ( handler : any , idx : number , originalArgs : any ) {
27
34
const { children } = this . props ;
28
- const child = React . Children . toArray ( children ) [ idx ] ;
35
+ // @ts -expect-error FIXME: Type 'string' is not assignable to type 'ReactElement<Props, string | JSXElementConstructor<any>>'.ts(2322)
36
+ const child : ChildElement = React . Children . toArray ( children ) [ idx ] ;
29
37
30
38
if ( child . props [ handler ] ) child . props [ handler ] ( ...originalArgs ) ;
39
+ // @ts -expect-error Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Readonly<Props> & Readonly<{ children?: ReactNode; }>'.ts(7053)
31
40
if ( this . props [ handler ] ) {
32
41
const maybeNode = child . props . nodeRef
33
42
? undefined
34
43
: ReactDOM . findDOMNode ( this ) ;
35
-
44
+ // @ts -expect-error FIXME: Argument of type 'Element | Text | null | undefined' is not assignable to parameter of type 'HTMLElement'.ts(2769)
36
45
this . props [ handler ] ( maybeNode ) ;
37
46
}
38
47
}
39
48
40
49
render ( ) {
41
- const { children, in : inProp , ...props } = this . props ;
42
- const [ first , second ] = React . Children . toArray ( children ) ;
50
+ const { children, in : inProp , ...props } : any = this . props ;
51
+ const [ first , second ] : any = React . Children . toArray ( children ) ;
43
52
44
53
delete props . onEnter ;
45
54
delete props . onEntering ;
@@ -68,9 +77,10 @@ class ReplaceTransition extends React.Component {
68
77
}
69
78
}
70
79
80
+ // @ts -expect-error To make TS migration diffs minimum, I've left propTypes here instead of defining a static property
71
81
ReplaceTransition . propTypes = {
72
82
in : PropTypes . bool . isRequired ,
73
- children ( props , propName ) {
83
+ children ( props : any , propName : any ) {
74
84
if ( React . Children . count ( props [ propName ] ) !== 2 )
75
85
return new Error (
76
86
`"${ propName } " must be exactly two transition components.`
0 commit comments