interface InputField {
readonly label : string;
readonly data : string;
readonly displayInline ?: boolean;
}
class FormField implements InputField {
readonly label : string;
readonly data : string;
readonly displayInline ?: boolean;
constructor(info : InputField) {
this.label = info.label;
this.data = info.data;
this.displayInline = info.displayInline;
}
}
When attempting to create a new instance of the FormField
class within another class like so,
class FormSection implements Section {
...
constructor(info : SectionInfo) {
...
this.fields = info.fieldData.map((field) => new FormField(field));
...
}
}
An error occurs with the message,
this.label = info.label;
^
TypeError: Cannot read property 'label' of undefined
If I print the value of info
inside the constructor(...)
method for FormField
, it shows the object correctly (with altered values for privacy),
{
data: '...information...',
label: '...description...',
displayInline: false
}
However, the error persists. The input provided to the FormSection
constructor is extracted from a JSON object via a websocket, which is also true for the FormField
constructor.