TS issues around auth.user object (possibly undefined) #1380
-
When I destructure the auth object in a controller and attempt to access the My issue is that every time I need to access something, I use the chaining operator, like I ended up coercing a user variable with the model class to use throughout, but I'm hoping this could be built-in somehow. const user = auth.user as User; I know it would be difficult to detect that a controller is behind an auth middleware, so I guess this typing would need to either be enforced by an in-controller switch or some other TS strategy. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @parker-codes! 👋 TypeScript offers the 👇🏼
auth.user!.some_field |
Beta Was this translation helpful? Give feedback.
Hey @parker-codes! 👋
TypeScript offers the
!
syntax that force the variable to be defined.