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

编程入门 行业动态 更新时间:2024-10-04 19:23:50

为什么得到 No overload matches this call ,Using typescript <a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误?"/>

为什么得到 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)=>{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~

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

回答如下:

更多推荐

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

本文发布于:2024-05-31 00:08:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   matches   overload   typescript   call

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!