Skip to content

Support Google Closure Compiler-style type expressions (JSDoc 3.2) #657

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

Closed
basickarl opened this issue Nov 28, 2020 · 4 comments
Closed

Comments

@basickarl
Copy link

I'm not sure if this should be put in #145 since that one specifically states TypeScript. Just tell me if it is!

According to the JSDoc 3.2 specification located here https://jsdoc.app/tags-type.html Google Closure Compiler-style type expressions should be supported.

Motivation

People are using TypeScript more and more, there is more information about this type of syntax rather than the old Object.<string, number> syntax which there is less information about.

Current behavior

Causes errors: Syntax error in type: [string, Message][]eslintjsdoc/valid-types

Desired behavior

No errors.

@brettz9
Copy link
Collaborator

brettz9 commented Nov 28, 2020

Your ESLint config either needs to use parser: '@typescript-eslint/parser' or have settings.jsdoc.mode set to 'typescript'.

@basickarl
Copy link
Author

basickarl commented Nov 28, 2020

@brettz9 Ah that is indeed interesting. I'm curious, why is the mode referred to as "typescript" when it is stated in the JSDoc specification? JSDoc isn't coupled to TypeScript afaiac (I am aware that TypeScript uses Google Closure Compiler-style type expressions, so it happens to work). Shouldn't the "mode" be referred to as "JSDoc-3.2"?

@brettz9
Copy link
Collaborator

brettz9 commented Nov 29, 2020

Firstly, I should say Object.<string, number> is not equivalent to [string, Message][]. The former (which is valid plain jsdoc) means an object with string keys and numeric values whereas the latter would mean an array of two-item arrays (with the first item in the tuple always being a string and the second item always being a Message). While the [] syntax for arrays is supported in plain jsdoc, such "tuples" as [string, Message] (indicating types within array positions) are not supported in jsdoc per jsdoc/jsdoc#1703 nor in Closure per google/closure-compiler#379 though they are in TypeScript. (Note that this "tuple" is different from the stage 2 JavaScript tuple proposal: https://github.com/tc39/proposal-record-tuple .)

@basickarl
Copy link
Author

Thank you for taking the time to explain this! I've been with TypeScript for a few years but want to move over to JavaScript + JSDoc and this helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants