hosseinmd / prettier-plugin-jsdoc

A Prettier plugin to format JSDoc comments.
MIT License
228 stars 29 forks source link

Type `{*}` is replaced with `{any}` #228

Open shadowspawn opened 6 months ago

shadowspawn commented 6 months ago

I am using {*} for the "any" type in my JSDoc which I think is the standard usage. This is used in examples on these pages:

prettier-plugin-jsdoc is replacing {*} with {any} which I have not seemed documented or used in examples for JSDoc, although presumably reasonable for TSDoc since a TypeScript type.

/**
- * @param {*} previous
+ * @param {any} previous
 */
shadowspawn commented 6 months ago

Could perhaps conditional the {any} on the tsdoc option?

shadowspawn commented 6 months ago

For interest, I was wondering where the {*} came from.

https://jsdoc.app/tags-type says:

A type expression can include the JSDoc namepath to a symbol (for example, myNamespace.MyClass); a built-in JavaScript type (for example, string); or a combination of these. You can use any Google Closure Compiler type expression, as well as several other formats that are specific to JSDoc.

https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System

Syntax Name Syntax Description
The ALL type * Indicates that the variable can take on any type. However, it is an error to attempt to do operations on a value of this type or access any properties on it. You also cannot assign it to any other type variable without a cast.
The ANY type ? Indicates that the variable can take on any type, and the compiler should not type-check any uses of it.
sxxov commented 5 months ago

Interesting, that means {*} would be anagolous to {unknown} instead of {any}.