Skip to content

Commit c3726c1

Browse files
committed
add cover for a generic type parameter with a default
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent 2b97121 commit c3726c1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

__tests__/handler.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ describe('typescript-react-function-component-props-handler', () => {
107107
expect(doc.props).toBeUndefined();
108108
});
109109

110+
// @TODO add definition for a generic type parameter with a default
111+
test('handles React.FC<Props> components with a generic type parameter with a default', () => {
112+
const doc = parseFixture('Select.tsx');
113+
114+
expect(doc.props).toBeUndefined();
115+
});
116+
110117
// Line 31 in index.js without type - can't be tested directly because of early return
111118
test('handles components without type', () => {
112119
const doc = parseFixture('ComponentWithoutType.tsx');

fixtures/Select.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
3+
type SelectOption<Value = string> = {
4+
value: Value;
5+
label: string;
6+
isDisabled?: boolean;
7+
};
8+
9+
type BaseSelectProps<Value> = {
10+
options: Array<SelectOption<Value>>;
11+
value: Value | null;
12+
onChange: (value: Value | null) => void;
13+
isClearable?: boolean;
14+
isMulti?: false;
15+
};
16+
17+
type MultiSelectProps<Value> = {
18+
options: Array<SelectOption<Value>>;
19+
value: Value[];
20+
onChange: (value: Value[]) => void;
21+
isMulti: true;
22+
};
23+
24+
type SelectProps<Value = string> =
25+
| BaseSelectProps<Value>
26+
| MultiSelectProps<Value>;
27+
28+
export const Select: React.FC<SelectProps> = ({ value }) => {
29+
return <span>{value}</span>;
30+
};

0 commit comments

Comments
 (0)