Skip to content

Commit 707ac00

Browse files
committed
NoInfer type type coverage
Signed-off-by: Winner95 <Winner95@users.noreply.github.com>
1 parent e55e42b commit 707ac00

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

__tests__/handler.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ describe('typescript-react-function-component-props-handler', () => {
8686
expect(doc.props.value.tsType.name).toBe("any");
8787
});
8888

89+
test('handles React.FC<Props> components with type prop type of NoInfer', () => {
90+
const doc = parseFixture('PrimaryButton.tsx');
91+
92+
expect(doc).toHaveProperty('props');
93+
expect(doc.props).toHaveProperty('as');
94+
expect(doc.props.as.tsType.name).toBe("T");
95+
});
96+
8997
// Line 31 in index.js without type - can't be tested directly because of early return
9098
test('handles components without type', () => {
9199
const doc = parseFixture('ComponentWithoutType.tsx');

fixtures/PrimaryButton.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, { ElementType } from 'react';
2+
3+
type DataAttributes = {
4+
[key: `data-${string}`]: string | number | undefined;
5+
};
6+
7+
type CommonButtonProps = {
8+
label: string;
9+
isDisabled?: boolean;
10+
isToggleButton?: boolean;
11+
} & DataAttributes;
12+
13+
type PrimaryButtonOwnProps<T extends React.ElementType> = CommonButtonProps & {
14+
as?: T;
15+
};
16+
17+
type PrimaryButtonProps<T extends React.ElementType> =
18+
PrimaryButtonOwnProps<T> &
19+
Omit<React.ComponentPropsWithRef<T>, keyof PrimaryButtonOwnProps<T>>;
20+
21+
export const PrimaryButton: React.FC<PrimaryButtonProps<ElementType>> = ({ label }) => {
22+
return <div>{label}</div>;
23+
};

0 commit comments

Comments
 (0)