Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for forwardRef<generics> #923

Merged
merged 8 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new test
  • Loading branch information
rvetere committed May 28, 2024
commit 165715d4ab25c79865a90b6500c02cb4cc7faaeb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ exports[`getTypeFromReactComponent > TypeScript > classes > finds props type in
]
`;

exports[`getTypeFromReactComponent > TypeScript > stateless > finds generic forwardRef type annotation 1`] = `
[
Node {
"type": "TSTypeReference",
"typeName": Node {
"name": "Props",
"type": "Identifier",
},
},
]
`;

exports[`getTypeFromReactComponent > TypeScript > stateless > finds multiple variable type annotation 1`] = `
[
Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ describe('getTypeFromReactComponent', () => {
expect(getTypeFromReactComponent(path)).toMatchSnapshot();
});

test('finds generic forwardRef type annotation', () => {
const path = parseTypescript
.statementLast<VariableDeclaration>(
`import React from 'react';
const x = React.forwardRef<HTMLDivElement, React.PropsWithChildren<Props>>((props, ref) => {})`,
)
.get('declarations')[0]
.get('init') as NodePath<ArrowFunctionExpression>;

expect(getTypeFromReactComponent(path)).toMatchSnapshot();
});

test('finds param inline type', () => {
const path = parseTypescript
.statementLast<VariableDeclaration>(
Expand Down