I may just be overlooking something, but I have the following model:
import { Brand } from './brand';
import { Plan } from './plan';
import { Venue } from './venue';
export class Subscription {
id: number;
brandId: number;
planId: number;
venueId: number;
state: number;
startDate: string;
endDate: string;
rolling: boolean;
overridePlan: boolean;
productCount: number;
price: number;
termsAgreed: boolean;
brand?: Brand;
plan?: Plan;
venue?: Venue;
get stateName(): string {
switch (this.state) {
case 0:
return 'Reserved';
case 1:
return 'Pending';
case 2:
return 'Active';
case 3:
return 'Cancelled';
case 4:
return 'Expired';
default:
return 'Unknown';
}
}
}
In this model, I am using a getter to retrieve the stateName. However, when attempting to create a new model:
const model: Subscription = {
id: 0,
brandId: 0,
planId: 0,
venueId: 0,
state: 0,
startDate: '',
endDate: '',
rolling: true,
overridePlan: false,
termsAgreed: false,
price: 0,
productCount: 0,
};
An error is raised indicating that stateName is missing in the new model. Shouldn't it be automatically populated by the getter?
The error message states:
Property 'stateName' is missing in type '{ id: number; brandId: number; planId: number; venueId: number; state: number; startDate: string; endDate: string; rolling: true; overridePlan: false; termsAgreed: false; price: number; productCount: number; }' but required in type 'Subscription'.
Is it really necessary to specify it manually?