akshgpt7 / akshgpt7/youtube-deno

Make filter type parameters mutually exclusive

Aperta
#4 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub
help wanted
Lingua principale
TypeScript
Stelle
48
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

For some methods, there are some parameters which are of the `filter` type, implying that *exactly one* of them has to be passed for one request. Example of filters: https://developers.google.com/youtube/v3/docs/activities/list#parameters.

This requires checking 2 things:
- At least one of the filters has been passed (filters cannot be 0 in number).
- Not more than one filter is passed (hence, mutually exclusive).

Currently there's no way to raise an error if the user enters more than one filter, or enters 0 filters.
This is a bit tricky to implement, and I've not yet found the correct approach to make this happen. The filters are clearly distinguished in the [API docs](https://developers.google.com/youtube/v3/docs) for each method.

The basic idea is to make the client library prompt the user/raise an error before the request is made if they have passed more than one filter/haven't passed any filter.
As of now, I could only think of making some kind of custom `filter` type, and check if exactly one parameter of the `filter` type exists in the params passed by the user (There can also be a better approach than this).

Supporting mutually exclusive groups has been opened as an issue in TypeScript itself, but it was rejected (https://github.com/microsoft/TypeScript/issues/38120, https://github.com/microsoft/TypeScript/issues/14094).

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.