Skip to content
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 JSDocs notation for index signatures, Object and object should be treated as the same #20555

Open
michaeljota opened this issue Dec 7, 2017 · 2 comments
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@michaeljota
Copy link

TypeScript Version: 2.7.0-dev.201xxxxx

Code

/**
 * Test.
 *
 * @param {object.<string, number>} obj An object.
 */
function func(obj) {
	console.log(obj);
}

Expected behavior:

obj should have a index signature as in #15105

Actual behavior:

obj is treated as any

Additional Info:

This was mentioned in the above issue, and it seems to be related to the way Typescript manage Object and object, but in JSDocs, they are treated similar.

@mhegazy mhegazy added Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation labels Jan 31, 2018
@mhegazy mhegazy added Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Apr 12, 2018
@brettz9
Copy link

brettz9 commented Jul 3, 2018

My concern with treating them "the same" in this context (if that means losing the TypeScript distinction between object and Object) is that with objects created by Object.create(null) not passing instanceof Object, object comes across more as the generic "typeof(val) === 'object'" (not excepting null, arrays or functions), whereas Object suggests to me an object that is an instance of Object.

@brettz9
Copy link

brettz9 commented Feb 3, 2022

My concern with this is that with objects created by Object.create(null) not passing instanceof Object, object comes across more as the generic "typeof(val) === 'object'" (not excepting null, arrays or functions), whereas Object suggests to me an object that is an instance of Object.

Besides breaking this helpful distinction of benefit to JavaScript users familiar with the type differences, treating object and Object as fully the same could be more confusing to TypeScript users and those transitioning to it.

While I normally support greater JSDoc compatibility, in my personal opinion, you should avoid introducing more distinctions between the TypeScript JSDoc flavor and the TypeScript proper syntaxes. It's bad enough for compatibility that one can't go reliably in the other direction, e.g., so we one use JSDoc types like Object<string, string> as a proper TypeScript type (yes, it is more verbose, but good for compatibility).

Of course if you just mean "Don't treat object.<string, number> as "any", then that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants