FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

docs(update) Fix issue in auth user code example #1171

Closed RobK closed 1 year ago

RobK commented 1 year ago

Add casting to prevent build error:

stories.controller.ts:47:5 - error TS2322: Type '{ [key: string]: any; } | null' is not assignable to type 'User'.
  Type 'null' is not assignable to type 'User'.

47     story.author = ctx.user;

Maybe there is a better way to fix this?

Issue

$ npm run build

src/app/controllers/api/stories.controller.ts:47:5 - error TS2322: Type '{ [key: string]: any; } | null' is not assignable to type 'User'.
  Type 'null' is not assignable to type 'User'.

47     story.author = ctx.user;
       ~~~~~~~~~~~~

47     story.author = ctx.user;

Solution and steps

Add casting

Checklist