@@ -462,9 +462,9 @@ ruleTester.run('prop-types', rule, {
462462 code : `
463463 class Hello extends React.Component {
464464 render() {
465- var {
465+ var {
466466 propX,
467- "aria-controls": ariaControls,
467+ "aria-controls": ariaControls,
468468 ...props } = this.props;
469469 return <div>Hello</div>;
470470 }
@@ -1346,7 +1346,7 @@ ruleTester.run('prop-types', rule, {
13461346 {
13471347 code : `
13481348 import type { FieldProps } from "redux-form"
1349-
1349+
13501350 type Props = {
13511351 label: string,
13521352 type: string,
@@ -3411,6 +3411,111 @@ ruleTester.run('prop-types', rule, {
34113411 ` ,
34123412 features : [ 'ts' , 'no-babel' ] ,
34133413 } ,
3414+ {
3415+ code : `
3416+ import React, { ForwardRefRenderFunction as X } from 'react'
3417+
3418+ type IfooProps = { e: string };
3419+ const Foo: X<HTMLDivElement, IfooProps> = function Foo (props, ref) {
3420+ const { e } = props;
3421+ return <div ref={ref}>hello</div>;
3422+ };
3423+ ` ,
3424+ features : [ 'ts' , 'no-babel' ] ,
3425+ } ,
3426+ {
3427+ code : `
3428+ import React, { ForwardRefRenderFunction } from 'react'
3429+
3430+ type IfooProps = { e: string };
3431+ const Foo: ForwardRefRenderFunction<HTMLDivElement, IfooProps> = function Foo (props, ref) {
3432+ const { e } = props;
3433+ return <div ref={ref}>hello</div>;
3434+ };
3435+ ` ,
3436+ features : [ 'ts' , 'no-babel' ] ,
3437+ } ,
3438+ {
3439+ code : `
3440+ import React, { ForwardRefRenderFunction } from 'react'
3441+
3442+ type IfooProps = { e: string };
3443+ const Foo: ForwardRefRenderFunction<HTMLDivElement, IfooProps> = (props, ref) => {
3444+ const { e } = props;
3445+ return <div ref={ref}>hello</div>;
3446+ };
3447+ ` ,
3448+ features : [ 'ts' , 'no-babel' ] ,
3449+ } ,
3450+ {
3451+ code : `
3452+ import React from 'react'
3453+
3454+ type IfooProps = { e: string };
3455+ const Foo= React.forwardRef<HTMLDivElement, IfooProps>((props, ref) => {
3456+ const { e } = props;
3457+ return <div ref={ref}>hello</div>;
3458+ });
3459+ ` ,
3460+ features : [ 'ts' , 'no-babel' ] ,
3461+ } ,
3462+ {
3463+ code : `
3464+ import React, { forwardRef } from 'react'
3465+
3466+ type IfooProps = { e: string };
3467+ const Foo= forwardRef<HTMLDivElement, IfooProps>((props, ref) => {
3468+ const { e } = props;
3469+ return <div ref={ref}>hello</div>;
3470+ });
3471+ ` ,
3472+ features : [ 'ts' , 'no-babel' ] ,
3473+ } ,
3474+ {
3475+ code : `
3476+ import React from 'react'
3477+ type IfooProps = { e: string };
3478+ const Foo= React.forwardRef<HTMLDivElement, IfooProps>(function Foo(props, ref) {
3479+ const { e } = props;
3480+ return <div ref={ref}>hello</div>;
3481+ });
3482+ ` ,
3483+ features : [ 'ts' , 'no-babel' ] ,
3484+ } ,
3485+ {
3486+ code : `
3487+ import React from 'react'
3488+ interface IfooProps { e: string }
3489+ const Foo= React.forwardRef<HTMLDivElement, IfooProps>(function Foo(props, ref) {
3490+ const { e } = props;
3491+ return <div ref={ref}>hello</div>;
3492+ });
3493+ ` ,
3494+ features : [ 'ts' , 'no-babel' ] ,
3495+ } ,
3496+ {
3497+ code : `
3498+ import React, { forwardRef } from 'react'
3499+ interface IfooProps { e: string }
3500+ const Foo= forwardRef<HTMLDivElement, IfooProps>(function Foo(props, ref) {
3501+ const { e } = props;
3502+ return <div ref={ref}>hello</div>;
3503+ });
3504+ ` ,
3505+ features : [ 'ts' , 'no-babel' ] ,
3506+ } ,
3507+ {
3508+ code : `
3509+ import React, { forwardRef as X } from 'react'
3510+
3511+ type IfooProps = { e: string };
3512+ const Foo= X<HTMLDivElement, IfooProps>((props, ref) => {
3513+ const { e } = props;
3514+ return <div ref={ref}>hello</div>;
3515+ });
3516+ ` ,
3517+ features : [ 'ts' , 'no-babel' ] ,
3518+ } ,
34143519 {
34153520 code : `
34163521 import React from 'react'
@@ -3430,7 +3535,7 @@ ruleTester.run('prop-types', rule, {
34303535 static propTypes = {
34313536 value: PropTypes.string
34323537 };
3433-
3538+
34343539 render() {
34353540 return <span>{this.props.value}</span>;
34363541 }
@@ -3830,7 +3935,7 @@ ruleTester.run('prop-types', rule, {
38303935 semver . satisfies ( babelEslintVersion , '< 9' ) ? {
38313936 code : `
38323937 class Hello extends React.Component {
3833- static propTypes: {
3938+ static propTypes: {
38343939 firstname: PropTypes.string
38353940 };
38363941 render() {
@@ -4019,8 +4124,8 @@ ruleTester.run('prop-types', rule, {
40194124 code : `
40204125 class Hello extends React.Component {
40214126 render() {
4022- var {
4023- "aria-controls": ariaControls,
4127+ var {
4128+ "aria-controls": ariaControls,
40244129 propX,
40254130 ...props } = this.props;
40264131 return <div>Hello</div>;
@@ -7139,6 +7244,76 @@ ruleTester.run('prop-types', rule, {
71397244 } ,
71407245 ] ,
71417246 features : [ 'ts' , 'no-babel' ] ,
7247+ } ,
7248+ {
7249+ code : `
7250+ import React from 'react'
7251+
7252+ type IfooProps = { e: string };
7253+ const Foo: React.ForwardRefRenderFunction<HTMLDivElement, IfooProps> = function Foo (props, ref) {
7254+ const { name } = props;
7255+ return <div ref={ref}>{name}</div>;
7256+ };
7257+ ` ,
7258+ errors : [
7259+ {
7260+ messageId : 'missingPropType' ,
7261+ data : { name : 'name' } ,
7262+ } ,
7263+ ] ,
7264+ features : [ 'ts' , 'no-babel' ] ,
7265+ } ,
7266+ {
7267+ code : `
7268+ import React from 'react'
7269+ type IfooProps = { k: string, a: number }
7270+ const Foo= React.forwardRef<HTMLDivElement, IfooProps>((props, ref) => {
7271+ return <div ref={ref}>{props.l}</div>;
7272+ });
7273+ ` ,
7274+ errors : [
7275+ {
7276+ messageId : 'missingPropType' ,
7277+ data : { name : 'l' } ,
7278+ } ,
7279+ ] ,
7280+ features : [ 'ts' , 'no-babel' ] ,
7281+ } ,
7282+ {
7283+ code : `
7284+ import React from 'react'
7285+
7286+ type IfooProps = { e: string };
7287+ const Foo= React.forwardRef<HTMLDivElement, IfooProps>(function Foo(props, ref) {
7288+ const { l } = props;
7289+ return <div ref={ref}>hello</div>;
7290+ });
7291+ ` ,
7292+ errors : [
7293+ {
7294+ messageId : 'missingPropType' ,
7295+ data : { name : 'l' } ,
7296+ } ,
7297+ ] ,
7298+ features : [ 'ts' , 'no-babel' ] ,
7299+ } ,
7300+ {
7301+ code : `
7302+ import React, { forwardRef } from 'react'
7303+
7304+ type IfooProps = { e: string };
7305+ const Foo= forwardRef<HTMLDivElement, IfooProps>(function Foo(props, ref) {
7306+ const { l } = props;
7307+ return <div ref={ref}>hello</div>;
7308+ });
7309+ ` ,
7310+ errors : [
7311+ {
7312+ messageId : 'missingPropType' ,
7313+ data : { name : 'l' } ,
7314+ } ,
7315+ ] ,
7316+ features : [ 'ts' , 'no-babel' ] ,
71427317 }
71437318 ) ) ,
71447319} ) ;
0 commit comments