TypeScript Version: 3.0.0-dev.20180711
Code
/** @typedef {object} T */
/** @type {T} */
const x = 0;
Expected behavior:
Error at x: 0 is not an object.
Actual behavior:
No error.
I think this is a result of Object/object being treated as any. For example, /** @typedef {{}} T */ produces an error.
In getTypeFromTypeNode, we have:
case SyntaxKind.ObjectKeyword:
return node.flags & NodeFlags.JavaScriptFile ? anyType : nonPrimitiveType
This was originally added in #17082. We could revisit this decision, but case-insensitive primitives and Object as any are good decisions in my opinion.
Solution may be to add a new type which is definitely the same as ts's object regardless of what kind of file it appears in.
Maybe type NonPrimitive = object in lib.d.ts?
can be closed as fixed by https://github.com/microsoft/TypeScript/pull/35661 ?
Maybe. #35661 only applies when noImplicitAny: true though.
I鈥檇聽like if聽there聽was a聽way to聽use the聽object聽type in聽JSDoc without聽needing to聽enable聽noImplicitAny.
@ExE-Boss you can use the type NonPrimitive = object in one of your own d.ts files. Unfortunately, lots of existing JS code uses object to mean any or unknown, even projects like webpack that compile regularly with typescript.