Closed yubinTW closed 1 year ago
when using request.session.user to get an user, typescript will find the type error
request.session.user
Property 'user' does not exist on type 'FastifySessionObject'.ts(2339)
because session field in FastifyRequest is FastifySessionObject type (from @fastify/session)
session
FastifyRequest
FastifySessionObject
@fastify/session
ref: https://github.com/fastify/session/blob/74615c3ba1ad71689c48896ac82ae3629bec5ea0/types/types.d.ts#L14
Extends the FastifySessionObject interface in @fastify/session, rather than Session interface in fastify
Session
fastify
Problem
when using
request.session.user
to get an user, typescript will find the type errorbecause
session
field inFastifyRequest
isFastifySessionObject
type (from@fastify/session
)ref: https://github.com/fastify/session/blob/74615c3ba1ad71689c48896ac82ae3629bec5ea0/types/types.d.ts#L14
Solution
Extends the
FastifySessionObject
interface in@fastify/session
, rather thanSession
interface infastify