I have a question regarding Angular/TypeScript. It may seem obvious, but I would like clarification.
What I'm doing is creating an interface and exporting it:
export interface MainObject {
location: string;
methodType: string;
securityLevel: string;
provider: string;
}
Then, I import it into a component and create an empty object:
public descriptorCreateFinal: MainObject
When attempting to assign a value to the object:
descriptorCreateFinal.location = 'someString';
An error occurs stating that 'location' is not declared.
However, if I declare the object like this:
public descriptorCreateFinal: MainObject = {
location: '',
methodType: '',
securityLevel: '',
provider: '',
}
I can assign a value to 'descriptorCreateFinal.location' without any issues.
My question is, do I really need to set values for all variables in the object during the declaration stage?