Is it possible to declare an object from a class with no default values?
i have a class that looks like below;
export class Month {
January: string;
February: string;
March: string;
...
}
mapMyPayload(specialMonths: Birthdays) {
let myMonth = new Month;
console.log(myMonth); //=> Month {}
// here I expect the Object.keys(myMonth)
// returns {January=undefined, February=undefined, ...}
// since I assume the new Month
// declares the myMonth as an object with undefined as its value
Object.keys(myMonth).forEach(m => {
// iterate thru the keys
// check if the month exists inside the specialMonths
// and is not null or undefined
if (specialMonths[m] != null) {
myMonth[m] = specialMonths[m];
);
return myMonth;
}
What I am trying to achieve is checking for any undefined
or null
in object and return this class.
I looked at many sample codes and documentation, either you have implicit constructor or explicit constructor you can declare you new class by using the new
infront of the class name, but that follows by they declare some values. So I think the instances do not exist before it is declared by some outside scope.