I am facing an issue with the FileInfo
class that implements the IFileInfo
interface. This class has an instance member function ext
and a function getExt()
. Within my component, there is a private method named openTempFolder()
which makes an HTTP call to retrieve an Array of FileInfo
. However, I keep receiving a TypeError
indicating that getExt()
is not a function, and calling ext
returns Undefined
. What could be the mistake in my implementation?
Here is the relevant code snippet,
export class FileInfo implements IFileInfo {
constructor(
public exists: boolean,
public length: number,
public physicalPath: string,
public name: string,
public lastModified: Date,
public isDirectory: boolean,
public ext: () => string,
) {
this.exists = exists;
this.length = length;
this.physicalPath = physicalPath;
this.name = name;
this.lastModified = lastModified;
this.isDirectory = isDirectory;
this.ext = () => {
return this.name.replace(/^.*\./, '');
};
}
getExt() {
return this.name.replace(/^.*\./, '');
}
}
When using the class in my component, it looks like this,
export class FileManagerComponent implements OnInit, OnDestroy {
@ViewChild('fileManager') public fileManager;
public contents: Array<FileInfo> = new Array<FileInfo>();
private unsubscribe: Subject<void> = new Subject();
....
private openTempFolder() {
this.httpService
.getRequest<Array<FileInfo>>('FileManager/OpenTemporaryDirectory/Uploads')
.subscribe((r: HttpResponse<Array<FileInfo>>) => {
this.contents = r.body;
this.contents.forEach(e => {
console.log(e.getExt()); // TypeError
console.log(e.ext()); // Undefined
});
});
}
}