Availability APIs: return "no" or empty string?
Opened this issue · 0 comments
domenic commented
Right now a lot of the code looks like
if (capabilities.langaugePairAvailable(...) !== "no") {
// ...
}
In particular, this will be the common pattern if you are OK accepting either "after-download"
or "readily"
.
There is a clever hack that at least one API uses to make this a bit more ergonomic. Instead of using "no"
to signal that you can't do something, use the empty string. Then you can do
if (capabilities.langaugePairAvailable(...)) {
// ...
}
because the empty string is falsy in JavaScript.
I'm a bit unsure whether we still consider this good practice.
I thought for a bit that maybe TypeScript wouldn't work with this sort of thing but it seems that it does.