简体   繁体   中英

Property 'user' does not exist on type '{ body: { name: any; description: any; date: string | number | Date; }; }'

I have a problem with my angular app, I am trying to connect my angular app to my DB, but I have this error

(Property 'user' does not exist on type '{ body: { name: any; description: any; date: string | number | Date; }; }'

can someone help me?

HERE IS MY CODE>

    router.post('/event', (req: { body: { name: any; description: any; date: string | number | Date; }; }, res: { status: (arg0: number) => { (): any; new(): any; json: { (arg0: { status: string; }): void; new(): any; }; }; }, next: any) => {
    const owner = req.user.email;
    db.query(
      'INSERT INTO events (owner, name, description, date) VALUES (?,?,?,?)',
      [owner, req.body.name, req.body.description, new Date(req.body.date)],
      (error: any) => {
        if (error) {
          console.error(error);
          res.status(500).json({status: 'error'});
        } else {
          res.status(200).json({status: 'ok'});
        }
      }
    );
  });
  1. use interface for more clarity.

interface Request { body: Body; user: any; }

interface Body {
    name: any;
    description: any;
    date: string | number | Date;
}
  1. Replace:

router.post('/event', (req: { body: { name: any; description: any; date: string | number | Date; }; },

with:

router.post('/event', (req: Request, ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM