diff --git a/README.md b/README.md index a86e0923e..545d55e6a 100644 --- a/README.md +++ b/README.md @@ -5576,6 +5576,18 @@ function quux (foo) { } // Settings: {"jsdoc":{"mode":"typescript"}} // Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object<>". + +/** + * + * @param {Object} param + * @return {Object | String} + */ +function abc(param) { + if (param.a) + return {}; + return 'abc'; +} +// Message: Invalid JSDoc @param "param" type "Object"; prefer: "object". ```` The following patterns are not considered problems: diff --git a/src/rules/checkTypes.js b/src/rules/checkTypes.js index 04483bb31..3a0a931fd 100644 --- a/src/rules/checkTypes.js +++ b/src/rules/checkTypes.js @@ -206,8 +206,8 @@ export default iterateJsdoc(({ // `unifyParentAndChildTypeChecks`) and we don't want // `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555 parentNode?.elements.length && ( - parentNode?.left.type === 'JsdocTypeName' && - parentNode?.left.value === 'Object' + parentNode?.left?.type === 'JsdocTypeName' && + parentNode?.left?.value === 'Object' ) ) ) { diff --git a/test/rules/assertions/checkTypes.js b/test/rules/assertions/checkTypes.js index e2503809e..05d393464 100644 --- a/test/rules/assertions/checkTypes.js +++ b/test/rules/assertions/checkTypes.js @@ -2356,6 +2356,46 @@ export default { }, }, }, + { + code: ` + /** + * + * @param {Object} param + * @return {Object | String} + */ + function abc(param) { + if (param.a) + return {}; + return 'abc'; + } + `, + errors: [ + { + line: 4, + message: 'Invalid JSDoc @param "param" type "Object"; prefer: "object".', + }, + { + line: 5, + message: 'Invalid JSDoc @return type "Object"; prefer: "object".', + }, + { + line: 5, + message: 'Invalid JSDoc @return type "String"; prefer: "string".', + }, + ], + output: ` + /** + * + * @param {object} param + * @return {Object | String} + */ + function abc(param) { + if (param.a) + return {}; + return 'abc'; + } + `, + }, ], valid: [ {