@@ -163,23 +163,46 @@ module.exports = {
163163 } ) ) ;
164164 }
165165
166+ /**
167+ * Handles Props defined in IntersectionTypeAnnotation nodes
168+ * e.g. type Props = PropsA & PropsB
169+ * @param {ASTNode } intersectionTypeAnnotation ObjectExpression node.
170+ * @returns {Object[] }
171+ */
172+ function getPropertiesFromIntersectionTypeAnnotationNode ( annotation ) {
173+ return annotation . types . reduce ( ( properties , type ) => {
174+ annotation = resolveGenericTypeAnnotation ( type ) ;
175+
176+ if ( annotation && annotation . id ) {
177+ annotation = findVariableByName ( annotation . id . name ) ;
178+ }
179+
180+ return properties . concat ( annotation . properties ) ;
181+ } , [ ] ) ;
182+ }
183+
166184 /**
167185 * Extracts a PropType from a TypeAnnotation node.
168186 * @param {ASTNode } node TypeAnnotation node.
169187 * @returns {Object[] } Array of PropType object representations, to be consumed by `addPropTypesToComponent`.
170188 */
171189 function getPropTypesFromTypeAnnotation ( node ) {
172- let properties ;
190+ let properties = [ ] ;
173191
174192 switch ( node . typeAnnotation . type ) {
175193 case 'GenericTypeAnnotation' :
176194 let annotation = resolveGenericTypeAnnotation ( node . typeAnnotation ) ;
177195
178- if ( annotation && annotation . id ) {
179- annotation = findVariableByName ( annotation . id . name ) ;
196+ if ( annotation && annotation . type === 'IntersectionTypeAnnotation' ) {
197+ properties = getPropertiesFromIntersectionTypeAnnotationNode ( annotation ) ;
198+ } else {
199+ if ( annotation && annotation . id ) {
200+ annotation = findVariableByName ( annotation . id . name ) ;
201+ }
202+
203+ properties = annotation ? ( annotation . properties || [ ] ) : [ ] ;
180204 }
181205
182- properties = annotation ? ( annotation . properties || [ ] ) : [ ] ;
183206 break ;
184207
185208 case 'UnionTypeAnnotation' :
@@ -314,7 +337,6 @@ module.exports = {
314337 if ( ! component ) {
315338 return ;
316339 }
317-
318340 addPropTypesToComponent ( component , getPropTypesFromTypeAnnotation ( node . typeAnnotation , context ) ) ;
319341 }
320342
0 commit comments