Good day. I'm new to Type Script, using VSCode.
Getting following errors:
error TS2322: Type '() => string' is not assignable to type 'string'.
error TS2322: Type '() => number' is not assignable to type 'number'.
The Code:
DTO.ts
interface DTO {
getId(): number;
getValue(): string;
}
export = DTO;
LinkedObject.ts
class LinkedObject {
public value: string = "Not Set";
public id: number = 0;
constructor(value?: string, id?: number) {
this.value = value;
this.id = id;
}
}
export = LinkedObject;
I am trying to instantiate LinkedObject
class using above mentioned interface methods:
TravelClientFormPopulator.ts
class TravelClientFormPopulator {
public populateComboBoxUsingDTOs(dataObjects: Array<DTO>, comboBoxID: string): void {
// Get the combo box
var selectElement = <HTMLSelectElement> document.getElementById(comboBoxID);
// Reset the options
selectElement.options.length = 0;
var linkedObjectsToAdd: LinkedObject[] = new Array<LinkedObject>();
var defaultLinkedObject: LinkedObject = new LinkedObject("Not Selected", 0);
linkedObjectsToAdd.push(defaultLinkedObject);
for (var i = 0; i < dataObjects.length; i++) {
var value: string = dataObjects[i].getValue; // Error here
var id: number = dataObjects[i].getId; // And here
var linkedObject: LinkedObject = new LinkedObject(value, id);
}
}
}
Any help will be highly appreciated.