microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.56k stars 12.43k forks source link

jsdoc "object." fails where "Object." works. #36872

Open illume opened 4 years ago

illume commented 4 years ago

Object.<string,number> works object.<string,number> fails

jsdoc eslint likes lower case object, see here: https://github.com/gajus/eslint-plugin-jsdoc/blob/master/.README/rules/check-types.md

IllusionMH commented 4 years ago

Most likely eslint-plugin-jsdoc should be fixed to support "map-like object" types instead of forcing object type which aren't equivalents.

Experimental playground with JS - need to open Errors tab to see reported errors

TS example

Or recommend to use Record<string, number> or {[key: string]: number} instead, however these are TS specific types and might be not supported by all tooling.

DanielRosenwasser commented 4 years ago

Might be part of the recent changes in 3.8 around how under noImplicitAny, object means the non-primitive type instead of Object. Thoughts @sandersn?

sandersn commented 4 years ago

@DanielRosenwasser This has never worked -- Object is the only thing special-cased with type parameters.

Lowercase object.<string,number> isn't documented on jsdoc.app. I did a quick node_modules fight of our user test suite, which is a decent selection of popular js libraries:

user  [master|✔]$ grep -r '{Object.<' | wc -l
599
✔ user  [master|✔]$ grep -r '{object.<' | wc -l
2

Both lowercase hits are from protobufjs/externs/fs.js. I personally don't think this is worth supporting unless the real-world usage rates change, or there is a lot of interest on this issue.

illume commented 4 years ago

@IllusionMH thanks for the tip about Record. I'm using that for now, since eslint jsdoc doesn't rewrite that type (but gives a type undefined warning), and tsc works.

I could make an issue with eslint-jsdoc... let me know?