Skip to content

req.params docs claim that this property can be an array #2100

@krzysdz

Description

@krzysdz

Description

When 4.x documentation was created the docs were copied from 3.x. One of the breaking changes was making req.params an object. This was partially corrected in #134, but the documentation still claims that if a regular expression is used, req.params is an array:

When you use a regular expression for the route definition, capture groups are provided in the array using `req.params[n]`, where `n` is the n<sup>th</sup> capture group. This rule is applied to unnamed wild card matches with string routes such as `/file/*`:

This isn't a huge problem, since values captured by unnamed capture groups have keys '0', '1', '2' etc. and req.params[n] access (where n is an integer), due to how JS works, will work (and involve a toString conversion).

This error is present both in 4.x and 5.x docs (and DefinitelyTyped - looks like this caused some problems, because they trusted the docs DefinitelyTyped/DefinitelyTyped#37502 (comment)).

Expectations

API docs (4.x and 5.x) should clearly explain that req.params always is an object and how keys are assigned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions