Is there a way in TypeScript/JavaScript to display an object's private properties using their getters instead of the actual property names?
For example, consider this TypeScript class:
class Vehicle {
constructor(private _brand: string, private _year: number) {}
get brand(): string {
return this._brand;
}
get year(): number {
return this._year;
}
set year(year: number) {
this._year = year;
}
set brand(brand: string) {
this._brand = brand;
}
}
const vehicle: Vehicle = new Vehicle('Toyota', 10);
console.log(vehicle);
Currently, when logging the 'vehicle' object, you would see:
[LOG]: Vehicle: {
"_brand": "Toyota",
"_year": 10
}
However, is it possible to achieve a log output like this:
[LOG]: Vehicle: {
"brand": "Toyota",
"year": 10
}