The request.query
object is of type ParsedQs
, which is defined as:
interface ParsedQs {
[key: string]: undefined
| string
| string[]
| ParsedQs
| ParsedQs[]
}
My interpretation of each type is as follows:
A value is
undefined
when it is not present in the parameters.
For example: accessingrequest.query.b
when the parameters are?a=1
.A value is a
string
when it appears once in the parameters. For example: accessingrequest.query.a
when the parameters are?a=1
.A value is a
string[]
when it appears multiple times in the parameters. For example: accessingrequest.query.a
when the parameters are?a=1&a=2
.
But when is a value considered a ParsedQs
itself?