I am new to TypeScript and am having trouble with basic class instantiation.
I have a namespace RecordsService with class Record declared inside of it. I want to be able to create Records within RecordsService, then access them via public methods from other methods and such.
export namespace RecordsService {
let records: Array<Record> = new Array();
function init () {
let record1 = new Record(new Date(), 1);
}
init();
export function getAllRecords() {
return records;
}
class Record {
constructor (public date: Date, public id: number) {
this.date = date;
this.id = id;
}
}
}
The above doesn't throw any transpiling error but when ran I get a console error with the below
TypeError: Record is not a constructor(…)
line that errors is let record1 = new Record(new Date(), 1);
How can I create a new Record in this case?
Plunker, view console log to see error: https://plnkr.co/edit/FNk8b1ZwA5HL3I7wAnTq?p=preview