#req.session.redirectTo = req.query.redirecTo; //typescript error

1 messages · Page 1 of 1 (latest)

foggy token
#

req.session.redirectTo = req.query.redirecTo;
//typescript error

Argument of type 'string | string[] | ParsedQs | ParsedQs[]' is not assignable to parameter of type 'string'

here is my declaration of d.ts

declare module "express-session" {
    interface SessionData {
        redirectTo: string;
    }
}
midnight sky
#

the error message is pretty explicit
in your code, you are doing req.session.redirectTo = req.query.redirecTo
except the first part is of type string (probably defined by your typings), and the other half is of type string | string[] | ParsedQs | ParsedQs[] (most likely coming from the library)

#

and you can't assign string | string[] | ParsedQs | ParsedQs[] to string
since you can't assign string[] to string, or ParsedQs to string, or ParsedQs[] to string

foggy token
#

yea thanks i saw that.... can you please explain with code solution and further readings Thanks7

midnight sky
#

well, first

#

why did you write your own typing file?

#

express-session has some, just use them npm i -D @types/express-session

foggy token
#

because it doesnt exist... already... the redirectTo

#

i did

midnight sky
#

hum, ok

foggy token
#

"@types/express-session": "^1.17.5",

midnight sky
#

but you should use the same types as req.query.redirecTo

#

since you are assigning one to the other

#

or else make sure req.query.redirecTo is a string and nothing else before assigning it to req.session.redirectTo

foggy token
#

ok

midnight sky
#

!resolved