How do you deal with this common pattern I’ve run into myself a bunch in typescript?
async RemoteCall(): Promise<Result> {
var res: Result = await RPC()
if (res) {
return res
}
}
Should I:
- Make
Result
a more robust type? (e.g. has data and errors attributes) - Change the return value to
Promise<Result | undefined>
? - Fill in Result with default values / 0 initialized?
- Something else? Monads?
I'm unfamiliar with current best practices surrounding both Javascript and Typescript, so any pointers would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire