Node.js version:
16.15.1
OS version:
Windows 11
Description:
Per the Koa docs, you can reassign to the ctx.query object. Whenever I do so, any typing that I have, is not preserved in future middleware or future calls to ctx.query (i.e. a value of [ 2 ] in the object just becomes '2' or the number 5 becomes the string '5'), although the actual assignment does seem to occur as indicated below by the fact that id becomes 4 after assignment, indicating something has changed.
Describe the bug
Node.js version: 16.15.1 OS version: Windows 11 Description:
Per the Koa docs, you can reassign to the ctx.query object. Whenever I do so, any typing that I have, is not preserved in future middleware or future calls to ctx.query (i.e. a value of [ 2 ] in the object just becomes '2' or the number 5 becomes the string '5'), although the actual assignment does seem to occur as indicated below by the fact that id becomes 4 after assignment, indicating something has changed.
Actual behavior
INITIAL QUERY OBJECT [Object: null prototype] { id: '2', arr: '5' } QUERY FROM JOI VALIDATION [Object: null prototype] { id: 2, arr: [ 5 ] } number CTX.QUERY AFTER ASSIGNMENT [Object: null prototype] { id: '4', arr: '5' } QUERY IN 2ND MIDDLEWARE [Object: null prototype] { id: '4', arr: '5' } string
Expected behavior
This is what I would expect from code example below.
INITIAL QUERY OBJECT [Object: null prototype] { id: '2', arr: '5' } QUERY FROM JOI VALIDATION [Object: null prototype] { id: 2, arr: [ 5 ] } number CTX.QUERY AFTER ASSIGNMENT [Object: null prototype] { id: 4, arr: [ 5 ] } QUERY IN 2ND MIDDLEWARE [Object: null prototype] { id: 4, arr: [ 5 ] } number
Code to reproduce
I've included a stack overflow entry and code sandbox that replicates this issue in addition to my project on my Windows 11 computer.
https://stackoverflow.com/questions/75368044/unable-to-reassign-ctx-query-in-a-koa-middleware