From 88ebd833bbde994bc373909e608be0b4bc01e80d Mon Sep 17 00:00:00 2001 From: DeviousCardi <115358213+DeviousCardi@users.noreply.github.com> Date: Sun, 22 Nov 2026 00:39:00 +0530 Subject: [PATCH] fix: resolve props defined only via React.FC and other React component type annotations (fixes #387) Components whose props are only expressed through a React function component type annotation (e.g. `interface Props {...}` referenced by `const C: React.FC = () => ...`) now get their props extracted. Root cause: findAssignedVariableType only recognized TypeScript TSTypeReference annotations, so Flow-parsed sources (GenericTypeAnnotation) and several component shapes yielded no props at all. Changes: - getTypeFromReactComponent: recognize React.FC/FunctionComponent/VFC/ VoidFunctionComponent (plus deprecated SFC/StatelessComponent) in both TS (TSTypeReference) and Flow (GenericTypeAnnotation) annotations - resolve props when a named function is assigned to an annotated variable (`const C: React.FC = Inner`) - resolve props from the generic argument of `React.memo(...)` - unwrapBuiltinTSPropTypes: also unwrap Flow GenericTypeAnnotation wrappers (React.PropsWithChildren/PropsWithRef/PropsWithoutRef) Regression tests: unit tests in getTypeFromReactComponent-test and codeTypeHandler-test, plus integration fixtures component_44-47. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe Signed-off-by: DeviousCardi <115358213+DeviousCardi@users.noreply.github.com> --- .changeset/fc-interface-props.md | 13 ++ .../__tests__/codeTypeHandler-test.ts | 132 ++++++++++++++++ .../getTypeFromReactComponent-test.ts.snap | 125 +++++++++++++++ .../getTypeFromReactComponent-test.ts | 84 ++++++++++ .../src/utils/getTypeFromReactComponent.ts | 149 ++++++++++++++++-- .../src/utils/unwrapBuiltinTSPropTypes.ts | 31 ++-- .../integration/__fixtures__/component_44.tsx | 24 +++ .../integration/__fixtures__/component_45.tsx | 16 ++ .../integration/__fixtures__/component_46.tsx | 20 +++ .../integration/__fixtures__/component_47.js | 18 +++ .../__snapshots__/integration-test.ts.snap | 106 +++++++++++++ 11 files changed, 696 insertions(+), 22 deletions(-) create mode 100644 .changeset/fc-interface-props.md create mode 100644 packages/react-docgen/tests/integration/__fixtures__/component_44.tsx create mode 100644 packages/react-docgen/tests/integration/__fixtures__/component_45.tsx create mode 100644 packages/react-docgen/tests/integration/__fixtures__/component_46.tsx create mode 100644 packages/react-docgen/tests/integration/__fixtures__/component_47.js diff --git a/.changeset/fc-interface-props.md b/.changeset/fc-interface-props.md new file mode 100644 index 00000000000..b6a2a338485 --- /dev/null +++ b/.changeset/fc-interface-props.md @@ -0,0 +1,13 @@ +--- +'react-docgen': patch +--- + +Resolve component props that are only defined through a React function +component type annotation, e.g. `interface Props {...}` used in +`const MyComponent: React.FC = () => ...` (issue #387). This now works +both for TypeScript-parsed and Flow-parsed sources, for the deprecated +`React.SFC`/`React.StatelessComponent` aliases, when a named function is +assigned to an annotated variable (`const C: React.FC = Inner`), and +for props expressed only via the generic argument of `React.memo(...)`. +Flow `React.PropsWithChildren`/`PropsWithRef`/`PropsWithoutRef` wrappers are +now unwrapped as well. diff --git a/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts b/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts index 7ab08002b57..630fa5d46ef 100644 --- a/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts +++ b/packages/react-docgen/src/handlers/__tests__/codeTypeHandler-test.ts @@ -167,6 +167,138 @@ describe('codeTypeHandler', () => { ); }); + describe('stateless component with props only in React.FC (issue #387)', () => { + test('flow: resolves props from an interface referenced by React.FC', () => { + const definition = parse + .statement( + `const MyComponent: React.FC = (props) => null; + var React = require('react'); + interface Props { + foo: string, + bar?: number, + }`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + codeTypeHandler(documentation, definition); + + expect(documentation.descriptors).toEqual({ + foo: { + description: '', + flowType: { name: 'string' }, + required: true, + }, + bar: { + description: '', + flowType: { name: 'number' }, + required: false, + }, + }); + }); + + test('ts: resolves props from an interface referenced by React.FC', () => { + const definition = parseTypescript + .statement( + `const MyComponent: React.FC = (props) => null; + import React from 'react'; + interface Props { + foo: string; + bar?: number; + }`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + codeTypeHandler(documentation, definition); + + expect(documentation.descriptors).toEqual({ + foo: { + description: '', + tsType: { name: 'string' }, + required: true, + }, + bar: { + description: '', + tsType: { name: 'number' }, + required: false, + }, + }); + }); + + test('ts: resolves props from an interface extending another interface', () => { + const definition = parseTypescript + .statement( + `const MyComponent: React.FC = () => null; + import React from 'react'; + interface Base { + baseProp: string; + } + interface Props extends Base { + foo: string; + }`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + codeTypeHandler(documentation, definition); + + expect(Object.keys(documentation.descriptors).sort()).toEqual([ + 'baseProp', + 'foo', + ]); + }); + + test('ts: resolves props from React.memo generics', () => { + const definition = parseTypescript + .statement( + `const MyComponent = React.memo((props) => null); + import React from 'react'; + interface Props { + foo: string; + }`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + const argument = definition.get( + 'arguments', + )[0] as NodePath; + + codeTypeHandler(documentation, argument); + + expect(documentation.descriptors).toEqual({ + foo: { + description: '', + tsType: { name: 'string' }, + required: true, + }, + }); + }); + + test('ts: resolves props when a named function is assigned to an annotated variable', () => { + const definition = parseTypescript.statement( + `function MyComponent() { return null; } + const Alias: React.FC = MyComponent; + import React from 'react'; + interface Props { + foo: string; + }`, + 0, + ); + + codeTypeHandler(documentation, definition); + + expect(documentation.descriptors).toEqual({ + foo: { + description: '', + tsType: { name: 'string' }, + required: true, + }, + }); + }); + }); + describe.each([ ['flow', parse], ['ts', parseTypescript], diff --git a/packages/react-docgen/src/utils/__tests__/__snapshots__/getTypeFromReactComponent-test.ts.snap b/packages/react-docgen/src/utils/__tests__/__snapshots__/getTypeFromReactComponent-test.ts.snap index 80528f7f15f..8acfde3d0e1 100644 --- a/packages/react-docgen/src/utils/__tests__/__snapshots__/getTypeFromReactComponent-test.ts.snap +++ b/packages/react-docgen/src/utils/__tests__/__snapshots__/getTypeFromReactComponent-test.ts.snap @@ -83,6 +83,71 @@ exports[`getTypeFromReactComponent > Flow > stateless > finds param type annotat ] `; +exports[`getTypeFromReactComponent > Flow > stateless > finds variable type annotation (FC) 1`] = ` +[ + Node { + "id": Node { + "name": "Props", + "type": "Identifier", + }, + "type": "GenericTypeAnnotation", + "typeParameters": null, + }, +] +`; + +exports[`getTypeFromReactComponent > Flow > stateless > finds variable type annotation (FunctionComponent) 1`] = ` +[ + Node { + "id": Node { + "name": "Props", + "type": "Identifier", + }, + "type": "GenericTypeAnnotation", + "typeParameters": null, + }, +] +`; + +exports[`getTypeFromReactComponent > Flow > stateless > finds variable type annotation (SFC) 1`] = ` +[ + Node { + "id": Node { + "name": "Props", + "type": "Identifier", + }, + "type": "GenericTypeAnnotation", + "typeParameters": null, + }, +] +`; + +exports[`getTypeFromReactComponent > Flow > stateless > finds variable type annotation (StatelessComponent) 1`] = ` +[ + Node { + "id": Node { + "name": "Props", + "type": "Identifier", + }, + "type": "GenericTypeAnnotation", + "typeParameters": null, + }, +] +`; + +exports[`getTypeFromReactComponent > Flow > stateless > unwraps React.PropsWithChildren in variable type annotation 1`] = ` +[ + Node { + "id": Node { + "name": "Props", + "type": "Identifier", + }, + "type": "GenericTypeAnnotation", + "typeParameters": null, + }, +] +`; + exports[`getTypeFromReactComponent > TypeScript > classes > finds props type in mixin base class params 1`] = ` [ Node { @@ -200,6 +265,42 @@ exports[`getTypeFromReactComponent > TypeScript > stateless > finds param type a ] `; +exports[`getTypeFromReactComponent > TypeScript > stateless > finds props type in React.memo generics 1`] = ` +[ + Node { + "type": "TSTypeReference", + "typeName": Node { + "name": "Props", + "type": "Identifier", + }, + }, +] +`; + +exports[`getTypeFromReactComponent > TypeScript > stateless > finds props type in React.memo generics without param annotation 1`] = ` +[ + Node { + "type": "TSTypeReference", + "typeName": Node { + "name": "Props", + "type": "Identifier", + }, + }, +] +`; + +exports[`getTypeFromReactComponent > TypeScript > stateless > finds props type when the component is assigned to an annotated variable 1`] = ` +[ + Node { + "type": "TSTypeReference", + "typeName": Node { + "name": "Props", + "type": "Identifier", + }, + }, +] +`; + exports[`getTypeFromReactComponent > TypeScript > stateless > finds variable type annotation (FC) > with MemberExpression 1`] = ` [ Node { @@ -248,6 +349,30 @@ exports[`getTypeFromReactComponent > TypeScript > stateless > finds variable typ ] `; +exports[`getTypeFromReactComponent > TypeScript > stateless > finds variable type annotation (SFC) 1`] = ` +[ + Node { + "type": "TSTypeReference", + "typeName": Node { + "name": "Props", + "type": "Identifier", + }, + }, +] +`; + +exports[`getTypeFromReactComponent > TypeScript > stateless > finds variable type annotation (StatelessComponent) 1`] = ` +[ + Node { + "type": "TSTypeReference", + "typeName": Node { + "name": "Props", + "type": "Identifier", + }, + }, +] +`; + exports[`getTypeFromReactComponent > TypeScript > stateless > finds variable type annotation (VFC) > with MemberExpression 1`] = ` [ Node { diff --git a/packages/react-docgen/src/utils/__tests__/getTypeFromReactComponent-test.ts b/packages/react-docgen/src/utils/__tests__/getTypeFromReactComponent-test.ts index c6dea8d6a25..ad2e549b3b1 100644 --- a/packages/react-docgen/src/utils/__tests__/getTypeFromReactComponent-test.ts +++ b/packages/react-docgen/src/utils/__tests__/getTypeFromReactComponent-test.ts @@ -1,6 +1,7 @@ import type { ArrowFunctionExpression, ClassDeclaration, + FunctionDeclaration, VariableDeclaration, } from '@babel/types'; import { parse, parseTypescript } from '../../../tests/utils'; @@ -130,6 +131,62 @@ describe('getTypeFromReactComponent', () => { expect(getTypeFromReactComponent(path)).toMatchSnapshot(); }); + + test.each(['SFC', 'StatelessComponent'])( + 'finds variable type annotation (%s)', + (name) => { + const path = parseTypescript + .statementLast( + `import React from 'react'; + const x: React.${name} = (props) => {}`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + expect(getTypeFromReactComponent(path)).toMatchSnapshot(); + }, + ); + + test('finds props type when the component is assigned to an annotated variable', () => { + const path = parseTypescript.statement( + `import React from 'react'; + function inner() { return null; } + const x: React.FC = inner;`, + 1, + ); + + expect(getTypeFromReactComponent(path)).toMatchSnapshot(); + }); + + test('finds props type in React.memo generics', () => { + const path = parseTypescript + .statementLast( + `import React from 'react'; + const x = React.memo((props) => {});`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + const argument = path.get( + 'arguments', + )[0] as NodePath; + + expect(getTypeFromReactComponent(argument)).toMatchSnapshot(); + }); + + test('finds props type in React.memo generics without param annotation', () => { + const path = parseTypescript + .statementLast( + `import React from 'react'; + const x = React.memo(function () { return null; });`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + const argument = path.get('arguments')[0] as NodePath; + + expect(getTypeFromReactComponent(argument)).toMatchSnapshot(); + }); }); describe('classes', () => { @@ -298,6 +355,33 @@ describe('getTypeFromReactComponent', () => { expect(getTypeFromReactComponent(path)).toMatchSnapshot(); }); + + test.each(['FunctionComponent', 'FC', 'SFC', 'StatelessComponent'])( + 'finds variable type annotation (%s)', + (name) => { + const path = parse + .statementLast( + `import React from 'react'; + const x: React.${name} = (props) => {}`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + expect(getTypeFromReactComponent(path)).toMatchSnapshot(); + }, + ); + + test('unwraps React.PropsWithChildren in variable type annotation', () => { + const path = parse + .statementLast( + `import React from 'react'; + const x: React.FC> = (props) => {}`, + ) + .get('declarations')[0] + .get('init') as NodePath; + + expect(getTypeFromReactComponent(path)).toMatchSnapshot(); + }); }); describe('classes', () => { diff --git a/packages/react-docgen/src/utils/getTypeFromReactComponent.ts b/packages/react-docgen/src/utils/getTypeFromReactComponent.ts index e502ef475bc..ea7c2b8a37a 100644 --- a/packages/react-docgen/src/utils/getTypeFromReactComponent.ts +++ b/packages/react-docgen/src/utils/getTypeFromReactComponent.ts @@ -4,6 +4,7 @@ import type Documentation from '../Documentation.js'; import getMemberValuePath from './getMemberValuePath.js'; import getTypeAnnotation from './getTypeAnnotation.js'; import getTypeParameters from './getTypeParameters.js'; +import isReactBuiltinCall from './isReactBuiltinCall.js'; import isReactComponentClass from './isReactComponentClass.js'; import isReactForwardRefCall from './isReactForwardRefCall.js'; import resolveGenericTypeAnnotation from './resolveGenericTypeAnnotation.js'; @@ -13,6 +14,7 @@ import type { FlowType, InterfaceDeclaration, InterfaceExtends, + Program, TSExpressionWithTypeArguments, TSInterfaceDeclaration, TSType, @@ -28,6 +30,21 @@ import getTypeIdentifier from './getTypeIdentifier.js'; import isReactBuiltinReference from './isReactBuiltinReference.js'; import unwrapBuiltinTSPropTypes from './unwrapBuiltinTSPropTypes.js'; +/** + * Names of the React types that describe a function component and take the + * props type as their first type argument, e.g. `React.FC`. + * Covers both the TypeScript (`React.FC`) and the Flow (`React.FC`) world, + * including the deprecated aliases. + */ +const FUNCTION_COMPONENT_TYPE_NAMES = [ + 'FunctionComponent', + 'FC', + 'VoidFunctionComponent', + 'VFC', + 'StatelessComponent', + 'SFC', +]; + function getStatelessPropsPath( componentDefinition: NodePath, ): NodePath | undefined { @@ -50,6 +67,90 @@ function getForwardRefGenericsType( return null; } +/** + * If the given type annotation is a React function component type, e.g. + * `React.FC` or `FunctionComponent` (in TypeScript as a + * `TSTypeReference` and in Flow as a `GenericTypeAnnotation`), this returns + * the path of the props type argument (`Props`). Otherwise `null` is + * returned. + */ +function getFunctionComponentPropsType( + typeAnnotation: NodePath, +): NodePath | null { + const isSupportedReference = + typeAnnotation.isTSTypeReference() || + typeAnnotation.isGenericTypeAnnotation(); + + if (!isSupportedReference) return null; + + const typeName = getTypeIdentifier(typeAnnotation); + + if (!typeName) return null; + + const isFunctionComponentType = FUNCTION_COMPONENT_TYPE_NAMES.some((name) => + isReactBuiltinReference(typeName, name), + ); + + if (!isFunctionComponentType) return null; + + const typeParameters = getTypeArguments(typeAnnotation); + + if ( + typeParameters.isTSTypeParameterInstantiation() || + typeParameters.isTypeParameterInstantiation() + ) { + const params = typeParameters.get('params') as NodePath[]; + + return params[0] ?? null; + } + + return null; +} + +/** + * Finds the props type of a component that is assigned to a variable with a + * React function component type annotation, e.g. + * `const MyComponent: React.FC = InnerComponent;`. + */ +function findReferencedVariableType( + componentDefinition: NodePath, +): NodePath | null { + if (!componentDefinition.isFunction()) return null; + + const program = componentDefinition.findParent((path) => + path.isProgram(), + ) as NodePath | null; + + if (!program) return null; + + let result: NodePath | null = null; + + program.traverse({ + VariableDeclarator(declaratorPath: NodePath) { + if (result) return; + + const init = declaratorPath.get('init'); + + if (!init.hasNode()) return; + + // Is this variable assigned our component? + if (resolveToValue(init).node !== componentDefinition.node) return; + + const typeAnnotation = getTypeAnnotation(declaratorPath.get('id')); + + if (!typeAnnotation) return; + + const propsType = getFunctionComponentPropsType(typeAnnotation); + + if (propsType) { + result = propsType; + } + }, + }); + + return result; +} + function findAssignedVariableType( componentDefinition: NodePath, ): NodePath | null { @@ -57,26 +158,42 @@ function findAssignedVariableType( path.isVariableDeclarator(), ) as NodePath | null; - if (!variableDeclarator) return null; + if (variableDeclarator) { + const typeAnnotation = getTypeAnnotation(variableDeclarator.get('id')); - const typeAnnotation = getTypeAnnotation(variableDeclarator.get('id')); + if (typeAnnotation) { + const propsType = getFunctionComponentPropsType(typeAnnotation); - if (!typeAnnotation) return null; + if (propsType) { + return propsType; + } + } + } - if (typeAnnotation.isTSTypeReference()) { - const typeName = typeAnnotation.get('typeName'); + // The component might be a named function that is assigned to an + // annotated variable elsewhere in the file, e.g. + // `function Inner() {...}; const C: React.FC = Inner;` + return findReferencedVariableType(componentDefinition); +} + +/** + * Finds the props type of a component wrapped in `React.memo(...)`, + * where the props are only expressed through the generic type argument of + * the `memo` call. + */ +function getMemoPropsType(componentDefinition: NodePath): NodePath | null { + const parent = componentDefinition.parentPath; + + if (parent && isReactBuiltinCall(parent, 'memo')) { + const typeParameters = getTypeArguments(parent); if ( - isReactBuiltinReference(typeName, 'FunctionComponent') || - isReactBuiltinReference(typeName, 'FC') || - isReactBuiltinReference(typeName, 'VoidFunctionComponent') || - isReactBuiltinReference(typeName, 'VFC') + typeParameters.isTSTypeParameterInstantiation() || + typeParameters.isTypeParameterInstantiation() ) { - const typeParameters = getTypeArguments(typeAnnotation); + const params = typeParameters.get('params') as NodePath[]; - if (typeParameters.isTSTypeParameterInstantiation()) { - return typeParameters.get('params')[0] ?? null; - } + return params[0] ?? null; } } @@ -193,6 +310,12 @@ export default (componentDefinition: NodePath): NodePath[] => { } } + const memoPropsType = getMemoPropsType(componentDefinition); + + if (memoPropsType) { + typePaths.push(memoPropsType); + } + const assignedVariableType = findAssignedVariableType(componentDefinition); if (assignedVariableType) { diff --git a/packages/react-docgen/src/utils/unwrapBuiltinTSPropTypes.ts b/packages/react-docgen/src/utils/unwrapBuiltinTSPropTypes.ts index 645b5737309..6d538206108 100644 --- a/packages/react-docgen/src/utils/unwrapBuiltinTSPropTypes.ts +++ b/packages/react-docgen/src/utils/unwrapBuiltinTSPropTypes.ts @@ -2,20 +2,33 @@ import getTypeArguments from './getTypeArguments.js'; import type { NodePath } from '@babel/traverse'; import isReactBuiltinReference from './isReactBuiltinReference.js'; +const BUILTIN_PROP_WRAPPER_NAMES = [ + 'PropsWithoutRef', + 'PropsWithRef', + 'PropsWithChildren', +]; + /** - * Unwraps NodePaths from the builtin TS types `PropsWithoutRef`, + * Unwraps NodePaths from the builtin types `PropsWithoutRef`, * `PropsWithRef` and `PropsWithChildren` and returns the inner type param. + * Both the TypeScript (`TSTypeReference`) and the Flow + * (`GenericTypeAnnotation`) representation are supported. * If none of the builtin types is detected the path is returned as-is */ export default function unwrapBuiltinTSPropTypes(typePath: NodePath): NodePath { - if (typePath.isTSTypeReference()) { - const typeName = typePath.get('typeName'); - - if ( - isReactBuiltinReference(typeName, 'PropsWithoutRef') || - isReactBuiltinReference(typeName, 'PropsWithRef') || - isReactBuiltinReference(typeName, 'PropsWithChildren') - ) { + const isSupportedReference = + typePath.isTSTypeReference() || typePath.isGenericTypeAnnotation(); + + if (isSupportedReference) { + const typeName = typePath.isTSTypeReference() + ? typePath.get('typeName') + : typePath.get('id'); + + const isBuiltinWrapper = BUILTIN_PROP_WRAPPER_NAMES.some((name) => + isReactBuiltinReference(typeName, name), + ); + + if (isBuiltinWrapper) { const typeParameters = getTypeArguments(typePath); if (typeParameters.hasNode()) { diff --git a/packages/react-docgen/tests/integration/__fixtures__/component_44.tsx b/packages/react-docgen/tests/integration/__fixtures__/component_44.tsx new file mode 100644 index 00000000000..d9d4d330593 --- /dev/null +++ b/packages/react-docgen/tests/integration/__fixtures__/component_44.tsx @@ -0,0 +1,24 @@ +import React from 'react'; + +interface BaseProps { + /** + * inherited from the base interface + */ + baseProp: string; +} + +interface Props extends BaseProps { + /** + * description of foo + */ + foo: string; + bar?: number; +} + +/** + * Props are only defined through the React.FC type annotation, + * not through the props argument (issue #387). + */ +const MyComponent: React.FC = () =>
; + +export default MyComponent; diff --git a/packages/react-docgen/tests/integration/__fixtures__/component_45.tsx b/packages/react-docgen/tests/integration/__fixtures__/component_45.tsx new file mode 100644 index 00000000000..899b25bffd4 --- /dev/null +++ b/packages/react-docgen/tests/integration/__fixtures__/component_45.tsx @@ -0,0 +1,16 @@ +import React from 'react'; + +interface Props { + /** + * description of foo + */ + foo: string; + bar?: number; +} + +/** + * Props are only defined through the generic type argument of React.memo. + */ +const MyComponent = React.memo((props) =>
); + +export default MyComponent; diff --git a/packages/react-docgen/tests/integration/__fixtures__/component_46.tsx b/packages/react-docgen/tests/integration/__fixtures__/component_46.tsx new file mode 100644 index 00000000000..a77b92840a4 --- /dev/null +++ b/packages/react-docgen/tests/integration/__fixtures__/component_46.tsx @@ -0,0 +1,20 @@ +import React from 'react'; + +interface Props { + /** + * description of foo + */ + foo: string; +} + +function InnerComponent() { + return
; +} + +/** + * The component is a named function assigned to a variable annotated + * with React.FC (issue #387). + */ +const MyComponent: React.FC = InnerComponent; + +export default MyComponent; diff --git a/packages/react-docgen/tests/integration/__fixtures__/component_47.js b/packages/react-docgen/tests/integration/__fixtures__/component_47.js new file mode 100644 index 00000000000..a071cf2cb97 --- /dev/null +++ b/packages/react-docgen/tests/integration/__fixtures__/component_47.js @@ -0,0 +1,18 @@ +// @flow +import React from 'react'; + +interface Props { + /** + * description of foo + */ + foo: string; + bar?: number; +} + +/** + * Props are only defined through the React.FC type annotation + * in flow-parsed code (issue #387). + */ +const MyComponent: React.FC = (props) =>
; + +export default MyComponent; diff --git a/packages/react-docgen/tests/integration/__snapshots__/integration-test.ts.snap b/packages/react-docgen/tests/integration/__snapshots__/integration-test.ts.snap index dec57998272..24249aaa8f2 100644 --- a/packages/react-docgen/tests/integration/__snapshots__/integration-test.ts.snap +++ b/packages/react-docgen/tests/integration/__snapshots__/integration-test.ts.snap @@ -2017,6 +2017,112 @@ exports[`integration > fixtures > processes component "component_43.tsx" without ] `; +exports[`integration > fixtures > processes component "component_44.tsx" without errors 1`] = ` +[ + { + "description": "Props are only defined through the React.FC type annotation, +not through the props argument (issue #387).", + "displayName": "MyComponent", + "methods": [], + "props": { + "bar": { + "description": "", + "required": false, + "tsType": { + "name": "number", + }, + }, + "baseProp": { + "description": "inherited from the base interface", + "required": true, + "tsType": { + "name": "string", + }, + }, + "foo": { + "description": "description of foo", + "required": true, + "tsType": { + "name": "string", + }, + }, + }, + }, +] +`; + +exports[`integration > fixtures > processes component "component_45.tsx" without errors 1`] = ` +[ + { + "description": "Props are only defined through the generic type argument of React.memo.", + "displayName": "MyComponent", + "methods": [], + "props": { + "bar": { + "description": "", + "required": false, + "tsType": { + "name": "number", + }, + }, + "foo": { + "description": "description of foo", + "required": true, + "tsType": { + "name": "string", + }, + }, + }, + }, +] +`; + +exports[`integration > fixtures > processes component "component_46.tsx" without errors 1`] = ` +[ + { + "description": "", + "displayName": "InnerComponent", + "methods": [], + "props": { + "foo": { + "description": "description of foo", + "required": true, + "tsType": { + "name": "string", + }, + }, + }, + }, +] +`; + +exports[`integration > fixtures > processes component "component_47.js" without errors 1`] = ` +[ + { + "description": "Props are only defined through the React.FC type annotation +in flow-parsed code (issue #387).", + "displayName": "MyComponent", + "methods": [], + "props": { + "bar": { + "description": "", + "flowType": { + "name": "number", + }, + "required": false, + }, + "foo": { + "description": "description of foo", + "flowType": { + "name": "string", + }, + "required": true, + }, + }, + }, +] +`; + exports[`integration > fixtures > processes component "flow-export-type.js" without errors 1`] = ` [ {