Why am I getting an undefined error for my calcUtilisation method when using an Abstract Class as the type in createStore? Is there a way to utilize a type for the data along with a method within the same class for createStore?
abstract class Account {
abstract name: String;
abstract creditUsed: number;
abstract creditLimit: number;
public calcUtilisation() {
return (this.creditUsed / this.creditLimit) * 100;
}
}
interface State {
accounts: [Account] | []
}
const [store, setStore] = createStore<State>({
accounts: []
});
const addAccount: Store<State> = (account: Account) => {
setStore({...store, accounts: [
...store.accounts,
account
]});
return store;
}
addAccount({ name:"Barclays", creditUsed: 11600, creditLimit: 13600 });
console.log(store.accounts.calcUtilisation)