Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Availability APIs: return "no" or empty string? #7

Open
domenic opened this issue May 10, 2024 · 0 comments
Open

Availability APIs: return "no" or empty string? #7

domenic opened this issue May 10, 2024 · 0 comments

Comments

@domenic
Copy link
Collaborator

domenic commented May 10, 2024

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.

@domenic domenic changed the title canXYZ() methods: return "no" or empty string? Availability APIs: return "no" or empty string? Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant