我想使用 Express TypeScript 创建 API,但是当我想使用 cors 时,它显示如下错误:
No overload matches this call.
The last overload gave the following error.
Argument of type 'RequestHandler<any>' is not assignable to parameter of type 'PathParams'.
Type 'RequestHandler<any>' is missing the following properties from type '(string | RegExp)[]': length, pop, push, concat, and 26 more.
Run Code Online (Sandbox Code Playgroud)
我使用yarn add cors express和安装了软件包yarn add @types/cors @types/express
这是我的代码:
const api = express();
const main = express();
api.use(cors({ origin: true }));
main.use(bodyParser.json());
main.use(bodyParser.urlencoded({ extended: false }));
main.use("/api/v1", api); …Run Code Online (Sandbox Code Playgroud)