Closed franklygeorgy closed 5 months ago
warning Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}` jsdoc/check-types
is being applied to our JavaScript files. Either the example given is wrong for JavaScript or this doesn't apply to JavaScript at all.
The example is correct for JavaScript; it denotes an object with string keys which map to string values. While this pattern is not part of the original JSDoc spec, the default mode we use and recommend is the TypeScript flavor of JSDoc. TypeScript tooling can be used with plain JavaScript as long as it follows the TypeScript flavor of JSDoc.
We don't want to follow this directive anyways so having an option to toggle it off would be appreciated.
You can disable the TypeScript flavor of JSDoc to use the original flavor by adding the following to your config:
settings: {
jsdoc: {
mode: 'jsdoc',
},
}
Closing as that should resolve, but feel free to comment further as needed.
Setting mode to jsdoc
gives us new errors like Syntax error in type: [Partial<App.Entity.SlaveState>, App.Medicine.Surgery.SimpleReaction]
and Syntax error in type: import("./setup.js").Settings
because we do use typescript notation in our jsdoc documentation. Again a toggle would be appreciated, but failing that I guess we will just have to add a lot of ignore comments to our documentation.
Take for example * @type {Object.<string, string>}
. Changing it to * @type {[Object: string]: string}
creates the error messages Syntax error in type: [Object: string]: [jsdoc/valid-types]
and '}' expected
on that line and the error message Type '{}' is not assignable to type '[Object: string]'
a few lines down at this.brand = {};
Never mind, I can't even use ignore comments. Because even though this error message reports that it is cause by jsdoc/check-types
using // eslint-disable-next-line jsdoc/check-types
or // eslint-disable-line jsdoc/check-types
does not make the error go away.
Firstly, you need curly brackets around the object, i.e.,
/**
* @type {{[Object: string]: string}}
*/
And I presume you would want to rename "Object" to "key" or something like that since that portion is indicating the key type. So:
/**
* @type {{[key: string]: string}}
*/
If you actually do need to disable (though I don't think you should), it should be like this:
/* eslint-disable jsdoc/valid-types */
/**
*
*/
Okay, I and my team were misunderstanding how that worked. Adding the second pair of brackets fixes all of our issues.
Thanks for the help!
warning Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}` jsdoc/check-types
is being applied to our JavaScript files. Either the example given is wrong for JavaScript or this doesn't apply to JavaScript at all.We don't want to follow this directive anyways so having an option to toggle it off would be appreciated.
ESLint Config
ESLint sample
Environment
eslint-plugin-jsdoc
version: 46.0.0