@@ -629,13 +629,14 @@ describe("react-declassify", () => {
629629 expect ( transform ( input ) ) . toBe ( output ) ;
630630 } ) ;
631631
632- it ( "transforms state types" , ( ) => {
632+ it ( "transforms state types (type alias) " , ( ) => {
633633 const input = dedent `\
634+ type Props = {};
634635 type State = {
635636 foo: number,
636637 bar: number,
637638 };
638- class C extends React.Component<{} , State> {
639+ class C extends React.Component<Props , State> {
639640 state = {
640641 foo: 1,
641642 bar: 2,
@@ -646,12 +647,46 @@ describe("react-declassify", () => {
646647 }
647648 ` ;
648649 const output = dedent `\
650+ type Props = {};
649651 type State = {
650652 foo: number,
651653 bar: number,
652654 };
653655
654- const C: React.FC<{}> = () => {
656+ const C: React.FC<Props> = () => {
657+ const [foo, setFoo] = React.useState<number>(1);
658+ const [bar, setBar] = React.useState<number>(2);
659+ return <button onClick={() => setBar(3)}>{foo}</button>;
660+ };
661+ ` ;
662+ expect ( transform ( input , { ts : true } ) ) . toBe ( output ) ;
663+ } ) ;
664+
665+ it ( "transforms state types (interface)" , ( ) => {
666+ const input = dedent `\
667+ interface Props {}
668+ interface State {
669+ foo: number,
670+ bar: number,
671+ }
672+ class C extends React.Component<Props, State> {
673+ state = {
674+ foo: 1,
675+ bar: 2,
676+ };
677+ render() {
678+ return <button onClick={() => this.setState({ bar: 3 })}>{this.state.foo}</button>;
679+ }
680+ }
681+ ` ;
682+ const output = dedent `\
683+ interface Props {}
684+ interface State {
685+ foo: number,
686+ bar: number,
687+ }
688+
689+ const C: React.FC<Props> = () => {
655690 const [foo, setFoo] = React.useState<number>(1);
656691 const [bar, setBar] = React.useState<number>(2);
657692 return <button onClick={() => setBar(3)}>{foo}</button>;
0 commit comments