-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In typescript mode, only allow {[key: string]: string}
and not object<>
, object.<>
, Object<>
and Object.<>
#1001
Comments
{s: string, n: number}
and not object<>
, object.<>
, Object<>
and Object.<>
{[key: string]: string}
and not object<>
, object.<>
, Object<>
and Object.<>
Regarding the /**
* @param {object} cfg
* @param {number} cfg.val Some desc.
* @param {string} cfg.anotherVal Another desc.
*/
function quux ({val, anotherVal}) {} But we could certainly forbid most of the others by default for TS, I think. |
@brettz9 I mean to disallow these: "preferredTypes": {
"Object<>": false,
"Object.<>": false,
"object<>": false,
"object.<>": false
} Those are JSDoc type syntaxes, that TypeScript does not have. See https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#types-1. So when in |
Understand, but I just want to be clear, you still want to allow plain Also, FWIW, TS does technically allow at least the |
Btw, I'm just not so sure that, although getting rid of even |
Agree it is uglier, at the start. But when getting used to it, it is not anymore. It is very subjective. The main goal of some projects I would suspect would be to go from pure JSDoc types to TypeScript types and then finally to pure TypeScript using I.e. the current JSDoc support TypeScript has, together with your awesome ESLint plugin, is that it gives a great incremental route towards pure TypeScript. Which can take years on large projects if done bit by bit. So forcing to use pure TypeScript types in JSDoc makes this easier to transition in the end since one can just copy&paste the types. Hope it made sense. But of course, it is up to you. I do think forcing index signatures goes into the spirit of using "typescript" |
Yes, and it makes sense. Even if not transitioning, with |
@brettz9 if you change the default, users who still prefer the old way can always set |
…res; fixes gajus#1001 BREAKING CHANGE: For typescript mode, one must use object shorthand or index signatures, e.g., `{[key: string]: number}` or `{a: string, b: number}`
You might want to look at #1012 with its test examples and docs to see if it matches your understanding. |
…res; fixes gajus#1001 BREAKING CHANGE: For typescript mode, one must use object shorthand or index signatures, e.g., `{[key: string]: number}` or `{a: string, b: number}`
…res; fixes gajus#1001 BREAKING CHANGE: For typescript mode, one must use object shorthand or index signatures, e.g., `{[key: string]: number}` or `{a: string, b: number}`
…res; fixes #1001 BREAKING CHANGE: For typescript mode, one must use object shorthand or index signatures, e.g., `{[key: string]: number}` or `{a: string, b: number}`
🎉 This issue has been resolved in version 41.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Motivation
TypeScript Do's and Dont's (https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types) says to never use
Object
(capital O). So when in typescript mode, only everobject
should be allowed as default, and notObject
.The reason is that a ton of users in our project always incorrectly uses
Object
in JSDoc, when it pretty much always should beobject
since we use typescript mode, which causes a lot of unnecessary code review comments.This was fixed in #800.
However, since jsdoc-type-pratt-parser/jsdoc-type-pratt-parser#101 has been fixed,
object<>
,object.<>
,Object<>
andObject.<>
should be disallowed as well.One can use
{[key: string]: string}
instead when in typescript mode. This should thus be the default.Current behavior
When eslint-plugin-jsdoc is set to
"mode": "typescript"
, then bothobject<>
,object.<>
,Object<>
andObject.<>
is allowed.Desired behavior
When
"mode": "typescript"
is set, only{[key: string]: string}
should be allowed by default.Alternatives considered
I could define this setting:
But the problem with that is that pretty much anyone using typescript mode would have to use that setting. It'd be much better to change the default, as that is an absolute "do and don't" to follow.
Those who want to allow
object<>
,object.<>
,Object<>
andObject.<>
etc. can already do that viapreferredTypes
.The text was updated successfully, but these errors were encountered: