I have one class:
export class DataAccess {
tableName: string;
constructor({ tableName }: { tableName: string }) {
this.tableName = tableName;
}
async getWhere(where: any, { single = false } = {}) {
const options: { limit?: number } = {};
if (single) {
options.limit = 1;
}
const results = await someDBobj[this.tableName].find(where, options);
if (!single) {
return results;
}
return results.length ? results[0] : null;
}
}
And a subclass:
import { DataAccess } from "./data-access";
type UsersTable = {
id: string;
email: string;
password: string;
createdAt: Date;
};
export default class Users extends DataAccess {
columns: { [P in keyof UsersTable]: string };
constructor() {
super({
tableName: "users"
});
this.columns = {
id: "id",
email: "email",
password: "password",
createdAt: "createdAt"
};
}
}
And using the Users class:
await users.getWhere(
{
email: user,
password
},
{
single: true
}
);
How can I set the Type of where: any in the parent DataAccess Class, so it knows that its the Users subclass that's called it?