useQueryParams: Serialize arrays using brackets and improve typing
Background
This MR has addresses two things:
- In Drupal, queries may expect arrays using bracket notation (c.q.
?foo[]=bar&foo[]=baz&foo[]=qux
. When using thequeryParams
variable to build an URL that bears a search query, array parameters with only one value were cast as strings (i.e.?foo=bar
instead of?foo[]=bar
. This caused bad request errors since Drupal would not expect a string, but an array. - In TypeScript projects, it was difficult to work with the existing typings since we used the
object
type, which refers to aReference Type
that may not have a key-value structure. As such, we encountered compilation errors during building.
What's changed
- Ensured that query parameters that receive array values are always serialised using bracket notation (see above)
- Made the JSDoc typings more accurate, which improves TypeScript interop
Edited by Pandu Supriyono