Skip to content

Commit 86b167f

Browse files
committed
Add support for objectOf
Fixes #74
1 parent ea87085 commit 86b167f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/utils/__tests__/getPropType-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ describe('getPropType', () => {
8585
value: [{name: 'custom', raw: 'foo'}],
8686
});
8787

88-
// custom type
8988
expect(getPropType(expression('instanceOf(Foo)'))).toEqual({
9089
name: 'instanceOf',
9190
value: 'Foo',
@@ -96,6 +95,11 @@ describe('getPropType', () => {
9695
value: {name: 'string'},
9796
});
9897

98+
expect(getPropType(expression('objectOf(string)'))).toEqual({
99+
name: 'objectOf',
100+
value: {name: 'string'},
101+
});
102+
99103
expect(getPropType(expression('shape({foo: string, bar: bool})'))).toEqual({
100104
name: 'shape',
101105
value: {

src/utils/getPropType.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ function getPropTypeArrayOf(argumentPath) {
6767
return type;
6868
}
6969

70+
function getPropTypeObjectOf(argumentPath) {
71+
var type: PropTypeDescriptor = {name: 'objectOf'};
72+
var subType = getPropType(argumentPath);
73+
74+
if (subType.name === 'unknown') {
75+
type.value = printValue(argumentPath);
76+
type.computed = true;
77+
} else {
78+
type.value = subType;
79+
}
80+
return type;
81+
}
82+
7083
function getPropTypeShape(argumentPath) {
7184
var type: PropTypeDescriptor = {name: 'shape', value: 'unknown'};
7285
if (!types.ObjectExpression.check(argumentPath.node)) {
@@ -116,6 +129,7 @@ var propTypes = {
116129
oneOfType: getPropTypeOneOfType,
117130
instanceOf: getPropTypeInstanceOf,
118131
arrayOf: getPropTypeArrayOf,
132+
objectOf: getPropTypeObjectOf,
119133
shape: getPropTypeShape,
120134
};
121135

0 commit comments

Comments
 (0)