Skip to content

typescript error with cors example on documentation #66

@mistersingh179

Description

@mistersingh179

When using the cors example code from the documentation page, it gives typescript error:

TS2345: Argument of type '(req: NextApiRequest, res: { statusCode?: number | undefined; setHeader(key: string, value: string): any; end(): any; }, next: (err?: any) => any) => void' is not assignable to parameter of type 'Middleware<NextApiRequest, NextApiResponse<any>> | Middleware<NextApiRequest, NextApiResponse<any>>[]'.   Type '(req: NextApiRequest, res: { statusCode?: number | undefined; setHeader(key: string, value: string): any; end(): any; }, next: (err?: any) => any) => void' is not assignable to type 'Middleware<NextApiRequest, NextApiResponse<any>>'.     Type 'void' is not assignable to type 'Promise<void>'.
import { use } from "next-api-middleware";
import cors from "cors";

const apiRouteThatOnlyNeedsCORS = async (req, res) => {
  ...
}

export default use(cors())(apiRouteThatOnlyNeedsCORS);

Please advice on how to resolve it. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions