The type of request.query
is ParsedQs
which has the following definition:
interface ParsedQs {
[key: string]: undefined
| string
| string[]
| ParsedQs
| ParsedQs[]
}
My guess for each types is the following:
A value is
undefined
when it isn't mentioned in the params.
For instance: readingrequest.query.b
when the params are?a=1
.A value is a
string
when it's mentioned once in the params. For instance: readingrequest.query.a
when the params are?a=1
.A value is a
string[]
when it's mentioned multiple times in the params. For instance: readingrequest.query.a
when the params are?a=1&a=2
.
But when is a value a ParsedQs
itself?
CodePudding user response:
The query ?a[x]=b&a[y]=c
is parsed into {"a":{"x":"b","y":"c"}}
.
And ?a[x]=b&a=c
is parsed into {"a":[{"x":"b"},"c"]}
.