There should be a compiler option like strictJSDocTypes or something to disable the object to any conversion present in TypeScript’s JSDoc parser.
I’m currently forced to use:
/** @typedef {NonNullable<Parameters<typeof Object.create>[0]>} obj */
to get a reference to TypeScript’s object type.
Any code where I use the above.
The following code creates an object with writable, configurable and non‑enumerable properties:
var ES = require("es-abstract");
var define = require("define-properties");
var $ObjectCreate = GetIntrinsic("%Object.create%", true);
/**
* @template {object} M
* @param {object | null} proto
* @param {M & ThisType<any>} [props]
* @return {object}
*/
function createObj(proto, props) {
var result = ES.ObjectCreate(proto);
if (arguments.length > 1) {
define(result, props);
}
return result;
}
All instances of object in the above code currently have to be replaced with the obj type alias.
My suggestion meets these guidelines:
@sandersn my understanding from https://github.com/microsoft/TypeScript-New-Handbook/pull/36 was that object was no longer rewritten to any as of 3.7, but it doesn’t seem like that’s the case?
Neither
objectnorObjecthave defined properties or string index
signatures, which means that they give too many errors to be useful in
Javascript. Until Typescript 3.7, both were rewritten toany, but we
found that few people usedobjectin JSDoc, and that more and more
JSDoc authors wanted to useobjectwith its Typescript meaning. The
rewriteObject -> anyis disabled when"noImplicitAny": true,
which the compiler takes as a signal that the code is being written
with Typescript in mind.
derp! yes, I misread the code when writing that new text. getIntendedTypeFromJSDocTypeReference doesn't handle object, so I assumed that a discussion I had earlier about turning off object -> any had resulted in the change. But actually it only operates on type references, not keywords. object is a keyword, so it's handled in getTypeFromTypeNode.
I need to track down that discussion, because I think it had some analysis of actual usage.
But in summary:
object to mean any the way we've observed Object being used.
Most helpful comment
But in summary:
objectto meananythe way we've observedObjectbeing used.