Skip to content

fix: correctly read description of inner types in arrayOf/objectOf #281

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

Merged
merged 1 commit into from
Jul 14, 2018
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
38 changes: 38 additions & 0 deletions src/utils/__tests__/getPropType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,44 @@ describe('getPropType', () => {
});
});

it('detects descriptions on nested types in arrayOf', () => {
expect(
getPropType(
expression(`arrayOf(
/**
* test2
*/
string
)`),
),
).toEqual({
name: 'arrayOf',
description: 'test2',
value: {
name: 'string',
},
});
});

it('detects descriptions on nested types in objectOf', () => {
expect(
getPropType(
expression(`objectOf(
/**
* test2
*/
string
)`),
),
).toEqual({
name: 'objectOf',
description: 'test2',
value: {
name: 'string',
},
});
});

it('detects descriptions on nested types in shapes', () => {
expect(
getPropType(
Expand Down
12 changes: 12 additions & 0 deletions src/utils/getPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ function getPropTypeOneOfType(argumentPath) {

function getPropTypeArrayOf(argumentPath) {
const type: PropTypeDescriptor = { name: 'arrayOf' };

const docs = getDocblock(argumentPath);
if (docs) {
type.description = docs;
}

const subType = getPropType(argumentPath);

if (subType.name === 'unknown') {
Expand All @@ -99,6 +105,12 @@ function getPropTypeArrayOf(argumentPath) {

function getPropTypeObjectOf(argumentPath) {
const type: PropTypeDescriptor = { name: 'objectOf' };

const docs = getDocblock(argumentPath);
if (docs) {
type.description = docs;
}

const subType = getPropType(argumentPath);

if (subType.name === 'unknown') {
Expand Down