E. Williams
E. Williams

Reputation: 425

Why typeof number|null is 'object'?

Reproducible code:

class MyObject{
    id: number|null = null
}

const a = new MyObject()
console.log(typeof a.id)

'object'

Is there a way to get the 'number' type from that property?

Edit:

I understand why typeof null is object. But my question is: is there a way (maybe reflection or something) to get that number|null complete type.

Upvotes: 0

Views: 34

Answers (1)

Johan
Johan

Reputation: 2972

If you want to get the type number of your new object, you need to assign a value to it.

Upvotes: 1

Related Questions