I am working with typescript for the first time and here is my problem.
I have the following class:
class FileSystemStatistics{
public number: number;
public name: string[];
public size: number;
public used: number;
public usedPercent: number;
public physicalLocation: string;
}
I analyze the PC for hardrives and as expected it returns an array of them. For testing purpose I just made the name property an array of the type string. Now i simply want to assign name[0] the name of first harddrive, name[1] the name of second harddrive etc.
I am doing the following to achieve this:
var fsObject = new FileSystemStatistics();
//testing if HDs are returned as an array consisting of objects. fs is the name (e.g. C:)
console.log(fsSize[0].fs); //--> C:
console.log(fsSize[1].fs); //--> G:
fsObject.name[0] = fsSize[0].fs;
fsObject.name[0] = fsSize[0].fs;
There are no mistakes marked in my code but when I want to run it I get the error:
"UnhandledPromiseRejectionWarning: TypeError: Cannot set property '0' of undefined"
I am pretty sure I am making a beginner mistake but I cannot solve it even after googling.