Closed
Description
TypeScript doesn't recognise object<>
, but understands Object<>
. By default, eslint-plugin-jsdoc
prefers the object
type over Object
. My intent is to prefer object
when the type is not using <>
, but if it is, prefer Object<>
.
- Is TypeScript / VS Code intellisense behavior incorrect, and we should push them for a speedy fix?
- Should the defaults take this TypeScript / VS Code intellisense behavior into account, and prefer
Object<>
? - How can that manually be configured, today?
Expected behavior
By default, the types enforced with jsdoc/check-types
should be compatible with TypeScript / VS Code intellisense.
Actual behavior
The object<>
type is not.
ESLint Config
{
plugins: ['jsdoc'],
rules: {
'jsdoc/check-types': 'error'
}
}
ESLint sample
To see the problem with the default prefered types, this will be an error:
/** @typedef {Object<string, boolean>} foo */
To try to allow Object<>
:
{
plugins: ['jsdoc'],
settings: {
jsdoc: {
preferredTypes: {
'object<>': 'Object',
},
},
},
rules: {
'jsdoc/check-types': 'error'
}
}
Unfortunately, that results a never ending circle of autofix causing another error:
Environment
- Node version: v15.12.0
- ESLint version v7.23.0
eslint-plugin-jsdoc
version: v32.3.0
Activity
brettz9 commentedon Mar 30, 2021
No, it's ok. We just felt that requiring "object" to include
Object.create(null)
was a better match since the lower-case form didn't suggest it needed to descend fromObject
(similar to how usingBoolean
andNumber
suggests wrapped objects).object
is for any non-primitive type per https://stackoverflow.com/a/49465172/271577 , but it seems it is not a generic (though neither isObject
, requiringRecord
for some reason--I'm not really deep into TS, but I'd think using the doc examples in the playground would show the jsdoc type on hover instead of "any".).But I'd generally be inclined to presume something like that, esp. being out for a while, is working as intended.
Yes, that is a good idea, though it seems it should perhaps be
Object.<>
with a dot since it is shown that way at https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#type (it mentions standard JSDoc but JSDoc doesn't really advertise support without the dot). We can look to the mode/parser if we get the underlying support.Unfortunately, we can't do this so easily with jsdoctypeparser's current AST traverser. It does not pass along info on the children or their being children (only the parent), so we'd have to do our own traversal.
brettz9 commentedon Jan 21, 2022
It seems we already make an exception to allow
Object
when themode
is "typescript" (or the parser is@typescript/eslint-parser
).brettz9 commentedon Jan 21, 2022
@jaydenseric : Maybe you want to offer your opinion on #800 ?
test(`check-types`): add case for gajus#709
test(`check-types`): add cases for gajus#709
brettz9 commentedon Feb 3, 2022
Closing in favor of carrying forward discussion on #800 . Hopefully to have a fix soon.