Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run tests
run: yarn test --ci
23 changes: 19 additions & 4 deletions __tests__/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@ describe('typescript-react-function-component-props-handler', () => {
expect(doc.displayName).toBe('TooltipTarget');
});

// Currently returns error for React.forwardRef(...) components
test('handles React.forwardRef(...) components - part 2', () => {
expect(() => parseFixture('ForwardedButton.tsx')).toThrow(
"Cannot read properties of undefined (reading 'length')"
);
const doc = parseFixture('ForwardedButton.tsx');

expect(doc.displayName).toBe('ForwardedButton');
expect(doc).toHaveProperty('props');
expect(doc.props).toHaveProperty('label');
expect(doc.props.label.tsType).toMatchObject({ name: 'string' });
expect(doc.props.label.required).toBe(true);
expect(doc.props.label).toHaveProperty('description');
expect(doc.props.label.description).toBe('Text to show inside the button');

expect(doc.props).toHaveProperty('onClick');
expect(doc.props.onClick.tsType).toMatchObject({ name: 'signature' });
expect(doc.props.onClick.tsType.type).toBe('function');
expect(doc.props.onClick.tsType.raw).toBe('() => void');
expect(doc.props.onClick.tsType.signature).toMatchObject({ arguments: [], return: { name: 'void' } });
expect(doc.props.onClick.required).toBe(false);

expect(doc.props.onClick).toHaveProperty('description');
expect(doc.props.onClick.description).toBe('Optional click handler');
});

test('handles React.FC<Props> components - AccessibleButton', () => {
Expand Down
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ function checkForProptypes(path, paramTypeName) {

function setParamsTypeDefinitionFromFunctionType(documentation, path) {
if (
path.parentPath.node.init &&
path.parentPath.node.init &&
Array.isArray(path.parentPath.node.init.params) &&
path.parentPath.node.init.params.length === 0
)
{
) {
return;
}
}

if (
path.node.type === 'ArrowFunctionExpression' &&
(
Expand Down