最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么得到 No overload matches this call ,Using typescript 错误?

网站源码admin33浏览0评论

为什么得到 No overload matches this call ,Using typescript 错误?

为什么得到 No overload matches this call ,Using typescript 错误?

import express from 'express';
import { Request, Response } from 'express';
import {User, IUser} from '../Models/User';
import {Organisation, IOrganisation} from '../Models/Organisation';
import {auth} from '../Middlewares/auth';
import { IGetUserAuthInfoRequest } from '../definition';
const orgRouter: express.Router = express.Router();


// create organisation route

orgRouter.post('/create', async (req: IGetUserAuthInfoRequest, res: Response)=>{
    try {
        const {name} = req.body;
        if(!name){
            res.status(400).json({
                message: 'Bad request'
            })
        }else{
            if(!req.user){
                res.status(401).json({
                    message: 'Unauthorized'
                })
            }
            else{
            const user = req.user;
            if(user && useranisations){
                const newOrg = new Organisation({
                    name: name,
                    creator: user._id,
                    admins : [user._id]
                });
                await newOrg.save();
                useranisations.push(newOrg._id);
                await user.save();  
                res.status(200).json({
                    newOrg,
                    message: 'Organisation created successfully'
                })

            }
        }
        }
    } catch (error) {
        res.status(500).json({
            message: 'Internal server error',
            error: error
        })
    }
}
)

// get all organisations route

orgRouter.get('/all', async (req: IGetUserAuthInfoRequest, res: Response)=>{
    try {
        const user   = req.user;
        const organisations = await Organisation.find({_id: {$in: useranisations}});
        res.status(200).json({
            organisations,
            message: 'Organisations fetched successfully'
        })
    } catch (error) {
        res.status(500).json({
            message: 'Internal server error',
            error: error
        })
    }
}
)




export default orgRouter;

--------------------------defination.ts-------------------------------------
import { Request } from "express"
export interface IGetUserAuthInfoRequest extends Request {
  user: any
}

error: 没有重载匹配这个调用。 最后一个重载给出了以下错误。 “(req: IGetUserAuthInfoRequest, res: Response) => Promise”类型的参数不可分配给“Application>”类型的参数。 类型“(req: IGetUserAuthInfoRequest, res: Response>) => Promise”缺少类型“Application>”中的以下属性:init、defaultConfiguration、engine、set 和其他 61 个。 12 orgRouter.post('/create', async (req: IGetUserAuthInfoRequest, res: Response)=>{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~

为什么会出现这个错误?我在请求的定义中犯了什么错误吗? 请澄清我。

回答如下:
发布评论

评论列表(0)

  1. 暂无评论