@@ -249,6 +249,7 @@ module.exports = {
249249 function _isDeclaredInComponent ( declaredPropTypes , keyList ) {
250250 for ( let i = 0 , j = keyList . length ; i < j ; i ++ ) {
251251 const key = keyList [ i ] ;
252+
252253 const propType = (
253254 declaredPropTypes && (
254255 // Check if this key is declared
@@ -261,7 +262,7 @@ module.exports = {
261262 // If it's a computed property, we can't make any further analysis, but is valid
262263 return key === '__COMPUTED_PROP__' ;
263264 }
264- if ( propType === true ) {
265+ if ( propType === true || typeof propType === 'object' && Object . keys ( propType ) . length === 0 ) {
265266 return true ;
266267 }
267268 // Consider every children as declared
@@ -308,6 +309,7 @@ module.exports = {
308309 function isDeclaredInComponent ( node , names ) {
309310 while ( node ) {
310311 const component = components . get ( node ) ;
312+
311313 const isDeclared =
312314 component && component . confidence === 2 &&
313315 _isDeclaredInComponent ( component . declaredPropTypes || { } , names )
@@ -483,7 +485,7 @@ module.exports = {
483485 * Creates the representation of the React props type annotation for the component.
484486 * The representation is used to verify nested used properties.
485487 * @param {ASTNode } annotation Type annotation for the props class property.
486- * @return {Object|Boolean } The representation of the declaration, true means
488+ * @return {Object } The representation of the declaration, empty object means
487489 * the property is declared without the need for further analysis.
488490 */
489491 function buildTypeAnnotationDeclarationTypes ( annotation ) {
@@ -492,7 +494,7 @@ module.exports = {
492494 if ( typeScope ( annotation . id . name ) ) {
493495 return buildTypeAnnotationDeclarationTypes ( typeScope ( annotation . id . name ) ) ;
494496 }
495- return true ;
497+ return { } ;
496498 case 'ObjectTypeAnnotation' :
497499 let containsObjectTypeSpread = false ;
498500 const shapeTypeDefinition = {
@@ -509,7 +511,7 @@ module.exports = {
509511
510512 // nested object type spread means we need to ignore/accept everything in this object
511513 if ( containsObjectTypeSpread ) {
512- return true ;
514+ return { } ;
513515 }
514516 return shapeTypeDefinition ;
515517 case 'UnionTypeAnnotation' :
@@ -520,7 +522,7 @@ module.exports = {
520522 for ( let i = 0 , j = annotation . types . length ; i < j ; i ++ ) {
521523 const type = buildTypeAnnotationDeclarationTypes ( annotation . types [ i ] ) ;
522524 // keep only complex type
523- if ( type !== true ) {
525+ if ( Object . keys ( type ) . length > 0 ) {
524526 if ( type . children === true ) {
525527 // every child is accepted for one type, abort type analysis
526528 unionTypeDefinition . children = true ;
@@ -532,7 +534,7 @@ module.exports = {
532534 }
533535 if ( unionTypeDefinition . children . length === 0 ) {
534536 // no complex type found, simply accept everything
535- return true ;
537+ return { } ;
536538 }
537539 return unionTypeDefinition ;
538540 case 'ArrayTypeAnnotation' :
@@ -544,7 +546,7 @@ module.exports = {
544546 } ;
545547 default :
546548 // Unknown or accepts everything.
547- return true ;
549+ return { } ;
548550 }
549551 }
550552
@@ -726,6 +728,7 @@ module.exports = {
726728 ignorePropsValidation = true ;
727729 return ;
728730 }
731+
729732 declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
730733 } ) ;
731734
0 commit comments