I'm working to implement an api using express/objection js and typescript.
I took a lot of inspiration from this repo: https://github.com/HappyZombies/brackette-alpha/tree/master/server/src
As the creator did, I want to have different interfaces for a same "component" ( eg: user ).
We can see here that he create different interfaces (here) and he uses them in his services as a returned promise (here) but there is no check that what he returned does match his interface. Eg: to match his promised interface here, he will only select the sql field that match his interface
public async findAll(): Promise<IUserMiminimum[]> {
let users;
try {
users = await this.usersModel.query().column('username', 'displayName');
} catch (err) {
this.logger.error(err);
throw err;
}
return users;
}
My questions are:
Thanks for reading.
Objection castTo() might help with that
const users= await User.query()
.column('username', 'displayName')
.castTo<IUser[]>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With