Skip to content

Commit f42e887

Browse files
committed
add complex interfaces
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent e065e4d commit f42e887

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

__tests__/handler.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ describe('typescript-react-function-component-props-handler', () => {
6868
expect(doc.props.size.tsType.raw).toBe("'small' | 'medium' | 'big'");
6969
});
7070

71+
test('handles React.FC<Props> components with complex type props', () => {
72+
const doc = parseFixture('LayoutSettings.tsx');
73+
74+
expect(doc).toHaveProperty('props');
75+
expect(doc.props).toHaveProperty('displaySettings');
76+
expect(doc.props).toHaveProperty('columnManager');
77+
expect(doc.props).toHaveProperty('onSettingsChange');
78+
expect(doc.props.displaySettings.tsType.signature.properties).toHaveLength(3);
79+
});
80+
7181
// Line 31 in index.js without type - can't be tested directly because of early return
7282
test('handles components without type', () => {
7383
const doc = parseFixture('ComponentWithoutType.tsx');

fixtures/LayoutSettings.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
3+
type DisplaySettings = {
4+
density?: 'compact' | 'cozy' | 'comfortable';
5+
primaryButton?: React.ReactElement;
6+
secondaryButton?: React.ReactElement;
7+
};
8+
9+
type ColumnManagerSettings = {
10+
searchHiddenColumns?: (event: React.ChangeEvent<HTMLInputElement>) => void;
11+
searchHiddenColumnsPlaceholder?: string;
12+
primaryButton?: React.ReactElement;
13+
secondaryButton?: React.ReactElement;
14+
};
15+
16+
type LayoutSettingsProps = {
17+
displaySettings?: DisplaySettings;
18+
columnManager?: ColumnManagerSettings;
19+
onSettingsChange?: (action: string, nextValue: object) => void;
20+
};
21+
22+
export const LayoutSettings: React.FC<LayoutSettingsProps> = ({
23+
onSettingsChange,
24+
}) => {
25+
return <button onClick={() => onSettingsChange}>action</button>;
26+
};

0 commit comments

Comments
 (0)