question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In JS, `object` is treated as 'any'

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ExE-Bosscommented, Feb 16, 2021

@sandersn I’ve personally been using:

/** @typedef {(typeof Object.create) extends (arg0: infer T, ...args: any) => any
	? (T extends null | undefined ? never : T) : never} obj */

Which is the inlined form of:

/** @typedef {NonNullable<Parameters<typeof Object.create>[0]>} obj */
1reaction
sandersncommented, Feb 21, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.is() - JavaScript - MDN Web Docs
The Object.is() static method determines whether two values are the same value.
Read more >
Why is the Object treated as an Array? - Stack Overflow
actually, arrays are objects, so it's arrays that are being treated like an object. Arrays can be thought of as objects that have...
Read more >
Working with objects in JavaScript · WebPlatform Docs
In JavaScript, almost everything is an object. All primitive types except null and undefined are treated as objects. They can be assigned properties...
Read more >
Objects - The Modern JavaScript Tutorial
We can immediately put some properties into {...} as “key: value” pairs: let user = { // an object ...
Read more >
JavaScript Objects
In JavaScript, almost "everything" is an object. ... In JavaScript, all values, except primitive values, are objects. Primitive values are: strings ("John Doe"), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found