I am implementing an application with Typescript and I have created a class with the following fields:
export class Car {
name: string;
model: string;
year: number;
saleDate: Date;
seller: User;
}
Now I create an instance of that class in this way:
var myCar = new Car();
Can I go through the fields of the class and get the format of each one? It would be something like this (but it does not work):
for(var field in myCar) {
console.log(typeof field);
}
// console result (it does not work):
// string
// string
// number
// Date
// User
This case actually always returns 'string'
. It makes sense, the key is really the name of the field, not the field itself.
Greetings.