@@ -3248,6 +3248,19 @@ ruleTester.run('prop-types', rule, {
32483248 ` ,
32493249 features : [ 'ts' , 'no-babel' ] ,
32503250 } ,
3251+ {
3252+ code : `
3253+ import React from 'react';
3254+
3255+ export interface PersonProps {
3256+ username: string;
3257+ }
3258+ const Person: React.FC<PersonProps> = (props): React.ReactElement => (
3259+ <div>{props.username}</div>
3260+ );
3261+ ` ,
3262+ features : [ 'ts' , 'no-babel' ] ,
3263+ } ,
32513264 {
32523265 code : `
32533266 import React from 'react';
@@ -3411,6 +3424,21 @@ ruleTester.run('prop-types', rule, {
34113424 ` ,
34123425 features : [ 'ts' , 'no-babel' ] ,
34133426 } ,
3427+ {
3428+ code : `
3429+ import React from 'react'
3430+
3431+ export interface Props {
3432+ age: number
3433+ }
3434+ const Hello: React.VoidFunctionComponent<Props> = function Hello(props) {
3435+ const { age } = props;
3436+
3437+ return <div>Hello {age}</div>;
3438+ }
3439+ ` ,
3440+ features : [ 'ts' , 'no-babel' ] ,
3441+ } ,
34143442 {
34153443 code : `
34163444 import React, { ForwardRefRenderFunction as X } from 'react'
@@ -3423,6 +3451,18 @@ ruleTester.run('prop-types', rule, {
34233451 ` ,
34243452 features : [ 'ts' , 'no-babel' ] ,
34253453 } ,
3454+ {
3455+ code : `
3456+ import React, { ForwardRefRenderFunction as X } from 'react'
3457+
3458+ export type IfooProps = { e: string };
3459+ const Foo: X<HTMLDivElement, IfooProps> = function Foo (props, ref) {
3460+ const { e } = props;
3461+ return <div ref={ref}>hello</div>;
3462+ };
3463+ ` ,
3464+ features : [ 'ts' , 'no-babel' ] ,
3465+ } ,
34263466 {
34273467 code : `
34283468 import React, { ForwardRefRenderFunction } from 'react'
@@ -3564,6 +3604,72 @@ ruleTester.run('prop-types', rule, {
35643604 }),
35653605 };
35663606 ` ,
3607+ } ,
3608+ {
3609+ code : `
3610+ import React, { forwardRef } from "react";
3611+
3612+ export type Props = { children: React.ReactNode; type: "submit" | "button" };
3613+
3614+ export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
3615+ <button ref={ref} className="MyClassName" type={props.type}>
3616+ {props.children}
3617+ </button>
3618+ ));
3619+ ` ,
3620+ features : [ 'ts' , 'no-babel' ] ,
3621+ } ,
3622+ {
3623+ code : `
3624+ import React, { forwardRef } from "react";
3625+
3626+ export type X = { num: number };
3627+ export type Props = { children: React.ReactNode; type: "submit" | "button" } & X;
3628+
3629+ export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
3630+ <button ref={ref} className="MyClassName" type={props.type} num={props.num}>
3631+ {props.children}
3632+ </button>
3633+ ));
3634+ ` ,
3635+ features : [ 'ts' , 'no-babel' ] ,
3636+ } ,
3637+ {
3638+ code : `
3639+ import React, { forwardRef } from "react";
3640+
3641+ export interface IProps {
3642+ children: React.ReactNode;
3643+ type: "submit" | "button"
3644+ }
3645+
3646+ export const FancyButton = forwardRef<HTMLButtonElement, IProps>((props, ref) => (
3647+ <button ref={ref} className="MyClassName" type={props.type}>
3648+ {props.children}
3649+ </button>
3650+ ));
3651+ ` ,
3652+ features : [ 'ts' , 'no-babel' ] ,
3653+ } ,
3654+ {
3655+ code : `
3656+ import React, { forwardRef } from "react";
3657+
3658+ export interface X {
3659+ num: number
3660+ }
3661+ export interface IProps extends X {
3662+ children: React.ReactNode;
3663+ type: "submit" | "button"
3664+ }
3665+
3666+ export const FancyButton = forwardRef<HTMLButtonElement, IProps>((props, ref) => (
3667+ <button ref={ref} className="MyClassName" type={props.type} num={props.num}>
3668+ {props.children}
3669+ </button>
3670+ ));
3671+ ` ,
3672+ features : [ 'ts' , 'no-babel' ] ,
35673673 }
35683674 ) ) ,
35693675
@@ -7336,6 +7442,140 @@ ruleTester.run('prop-types', rule, {
73367442 } ,
73377443 ] ,
73387444 features : [ 'ts' , 'no-babel' ] ,
7445+ } ,
7446+ {
7447+ code : `
7448+ import React, { forwardRef } from "react";
7449+
7450+ export type Props = { children: React.ReactNode; type: "submit" | "button" };
7451+
7452+ export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
7453+ <button ref={ref} className="MyClassName" type={props.nonExistent}>
7454+ {props.children}
7455+ </button>
7456+ ));
7457+ ` ,
7458+ errors : [
7459+ {
7460+ messageId : 'missingPropType' ,
7461+ data : { name : 'nonExistent' } ,
7462+ } ,
7463+ ] ,
7464+ features : [ 'ts' , 'no-babel' ] ,
7465+ } ,
7466+ {
7467+ code : `
7468+ import React, { forwardRef } from "react";
7469+
7470+ export interface IProps { children: React.ReactNode; type: "submit" | "button" };
7471+
7472+ export const FancyButton = forwardRef<HTMLButtonElement, IProps>((props, ref) => (
7473+ <button ref={ref} className="MyClassName" type={props.nonExistent}>
7474+ {props.children}
7475+ </button>
7476+ ));
7477+ ` ,
7478+ errors : [
7479+ {
7480+ messageId : 'missingPropType' ,
7481+ data : { name : 'nonExistent' } ,
7482+ } ,
7483+ ] ,
7484+ features : [ 'ts' , 'no-babel' ] ,
7485+ } ,
7486+ {
7487+ code : `
7488+ import React from 'react';
7489+
7490+ export interface PersonProps {
7491+ username: string;
7492+ }
7493+ const Person: React.FC<PersonProps> = (props): React.ReactElement => (
7494+ <div>{props.nonExistent}</div>
7495+ );
7496+ ` ,
7497+ errors : [
7498+ {
7499+ messageId : 'missingPropType' ,
7500+ data : { name : 'nonExistent' } ,
7501+ } ,
7502+ ] ,
7503+ features : [ 'ts' , 'no-babel' ] ,
7504+ } ,
7505+ {
7506+ code : `
7507+ import React, { FC } from 'react';
7508+
7509+ export interface PersonProps {
7510+ username: string;
7511+ }
7512+ const Person: FC<PersonProps> = (props): React.ReactElement => (
7513+ <div>{props.nonExistent}</div>
7514+ );
7515+ ` ,
7516+ errors : [
7517+ {
7518+ messageId : 'missingPropType' ,
7519+ data : { name : 'nonExistent' } ,
7520+ } ,
7521+ ] ,
7522+ features : [ 'ts' , 'no-babel' ] ,
7523+ } ,
7524+ {
7525+ code : `
7526+ import React, { FC as X } from 'react';
7527+
7528+ export interface PersonProps {
7529+ username: string;
7530+ }
7531+ const Person: X<PersonProps> = (props): React.ReactElement => (
7532+ <div>{props.nonExistent}</div>
7533+ );
7534+ ` ,
7535+ errors : [
7536+ {
7537+ messageId : 'missingPropType' ,
7538+ data : { name : 'nonExistent' } ,
7539+ } ,
7540+ ] ,
7541+ features : [ 'ts' , 'no-babel' ] ,
7542+ } ,
7543+ {
7544+ code : `
7545+ import React, { ForwardRefRenderFunction as X } from 'react'
7546+
7547+ export type IfooProps = { e: string };
7548+ const Foo: X<HTMLDivElement, IfooProps> = function Foo (props, ref) {
7549+ const { nonExistent } = props;
7550+ return <div ref={ref}>hello</div>;
7551+ };
7552+ ` ,
7553+ errors : [
7554+ {
7555+ messageId : 'missingPropType' ,
7556+ data : { name : 'nonExistent' } ,
7557+ } ,
7558+ ] ,
7559+ features : [ 'ts' , 'no-babel' ] ,
7560+ } ,
7561+ {
7562+ code : `
7563+ import React from 'react';
7564+
7565+ export interface PersonProps {
7566+ username: string;
7567+ }
7568+ const Person: React.VoidFunctionComponent<PersonProps> = (props): React.ReactElement => (
7569+ <div>{props.nonExistent}</div>
7570+ );
7571+ ` ,
7572+ errors : [
7573+ {
7574+ messageId : 'missingPropType' ,
7575+ data : { name : 'nonExistent' } ,
7576+ } ,
7577+ ] ,
7578+ features : [ 'ts' , 'no-babel' ] ,
73397579 }
73407580 ) ) ,
73417581} ) ;
0 commit comments