Skip to content

Commit 2314649

Browse files
authored
fix: correctly read description of inner types in arrayOf/objectOf (#281)
1 parent 8b30234 commit 2314649

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/utils/__tests__/getPropType-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,44 @@ describe('getPropType', () => {
266266
});
267267
});
268268

269+
it('detects descriptions on nested types in arrayOf', () => {
270+
expect(
271+
getPropType(
272+
expression(`arrayOf(
273+
/**
274+
* test2
275+
*/
276+
string
277+
)`),
278+
),
279+
).toEqual({
280+
name: 'arrayOf',
281+
description: 'test2',
282+
value: {
283+
name: 'string',
284+
},
285+
});
286+
});
287+
288+
it('detects descriptions on nested types in objectOf', () => {
289+
expect(
290+
getPropType(
291+
expression(`objectOf(
292+
/**
293+
* test2
294+
*/
295+
string
296+
)`),
297+
),
298+
).toEqual({
299+
name: 'objectOf',
300+
description: 'test2',
301+
value: {
302+
name: 'string',
303+
},
304+
});
305+
});
306+
269307
it('detects descriptions on nested types in shapes', () => {
270308
expect(
271309
getPropType(

src/utils/getPropType.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ function getPropTypeOneOfType(argumentPath) {
8686

8787
function getPropTypeArrayOf(argumentPath) {
8888
const type: PropTypeDescriptor = { name: 'arrayOf' };
89+
90+
const docs = getDocblock(argumentPath);
91+
if (docs) {
92+
type.description = docs;
93+
}
94+
8995
const subType = getPropType(argumentPath);
9096

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

100106
function getPropTypeObjectOf(argumentPath) {
101107
const type: PropTypeDescriptor = { name: 'objectOf' };
108+
109+
const docs = getDocblock(argumentPath);
110+
if (docs) {
111+
type.description = docs;
112+
}
113+
102114
const subType = getPropType(argumentPath);
103115

104116
if (subType.name === 'unknown') {

0 commit comments

Comments
 (0)