apollographql / apollographql/datasource-rest
Type signature for params is too narrow
- Dominant language
- TypeScript
- Stars
- 48
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
In the code, the params type is defined as follows:
```ts
/**
* URL search parameters can be provided either as a record object (in which
* case keys with `undefined` values are ignored) or as an URLSearchParams
* object. If you want to specify a parameter multiple times, use
* URLSearchParams with its "array of two-element arrays" constructor form.
* (The URLSearchParams object is globally available in Node, and provided to
* TypeScript by @types/node.)
*/
params?: Record | URLSearchParams;
```
but in the docs the following example is used:
```ts
async getMostViewedMovies(limit = 10) {
const data = await this.get('movies', {
params: {
per_page: limit,
order_by: 'most_viewed',
},
});
return data.results;
}
```
which would fail the type checking because `Type number is not assignable to type string.`
The params object should be something more like:
```ts
params?: Record | URLSearchParams;
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the params type declaration shown in the issue and compare it with the getMostViewedMovies documentation example. Verify the example with TypeScript, then confirm that the params object accepts the documented numeric value while retaining the existing string, undefined, and URLSearchParams forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100