I have class like
export class Model {
name: string;
size: number;
}
if I try to get typeof these variables like below, it returns undefined.
model: Model;
.
.
.
this.model = new Model();
console.log(typeof (this.model.size));
I tried to make class with constructor.
export class Model{
constructor(public q: string, public size?: number) {}
}
And I tried to get type of variables.
this.model = new Model('', null);
console.log(this.model.size)
It returns object. I tried toType method
toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
And
console.log( this.toType (this.model.size));
It returns null.
How can I get variable type correctly without assigning values?