In the process of developing a component to manage information about fields for form use, I am in need of storing different data objects in order to establish generic procedures for handling the data.
export class DataField<T> {
/**
* Field name (e.g., database column name, JSON field)
*/
private Name_: string;
private Size_: number;
/**
* The data type associated with this field. For example: String, Boolean, etc. This is internally set and not defined by an external reference
*/
private Type_: T;
/**
* Constructor method
* @param FieldName string Name of the Field
* @param FieldSize number Field Size
*/
constructor(FieldName:string, FieldSize:number) {
this.Name_ = FieldName;
this.Size_ = FieldSize;
}
/**
* Retrieve the data type of the value
* @returns string The type of the value
*/
get Type(): string {
return (typeof this.Type_).toString();
}
}
The issue I am encountering is that the Type_ field is not initialized with any value, therefore it remains undefined all the time. When creating a DataField instance with a generic type, it may look like this:
new DataField<string>('FullName', 32);
With the generic type T now being string
, my objective is to properly assign a value to the Type_ variable so that the call to get Type()
will correctly return a string.