TS2345 [错误]:'{ 深度:和 属性 'response' 类型的参数在类型 '{ 上不存在响应:任何; }' 在 Deno 上编译

TS2345 [ERROR]: Argument of type '{ depth: and Property 'response' does not exist on type '{ respnse: any; }' on Deno compile

这是我第一次使用 Deno,我是从 youtube 和文档中学习的。我想做的第一件事是使用这个脚本使用 deno 制作一个简单的本地服务器。

Route.ts

import {Router} from "https://deno.land/x/oak/mod.ts";

const route = new Router();

route.get('/',async({
    response
}: {
    respnse : any;
}) => {
    response.status = 200;
    response.body = {
        message: "welcome"
    }
});

export default route;

这是我的 server.ts

import {Application} from  "https://deno.land/x/oak/mod.ts";
import route from './src/routes/router.ts';
const app = new Application();
const port = 3000;

app.use(route.routes());
app.use(route.allowedMethods());

console.log("server is running");

await app.listen({port})

我运行server.ts用这个命令

C:\laragon\bin\deno>deno run D:\deno_mongo\server.ts

但是我在编译数据时遇到了这个错误

Compile file:///D:/deno_mongo/server.ts
error: TS2769 [ERROR]: No overload matches this call.
  Overload 1 of 2, '(name: string, path: string, ...middleware: RouterMiddleware<Record<string | number, string | undefined>, Record<string, any>>[]): Router<Record<string | number, string | undefined>, Record<...>>', gave the following error.
    Argument of type '({ response }: {    respnse: any;}) => Promise<void>' is not assignable to parameter of type 'string'.
  Overload 2 of 2, '(path: string, ...middleware: RouterMiddleware<Record<string | number, string | undefined>, Record<string, any>>[]): Router<Record<string | number, string | undefined>, Record<...>>', gave the following error.
    Argument of type '({ response }: {    respnse: any;}) => Promise<void>' is not assignable to parameter of type 'RouterMiddleware<Record<string 
| number, string | undefined>, Record<string, any>>'.
      Types of parameters '__0' and 'context' are incompatible.
        Property 'respnse' is missing in type 'RouterContext<Record<string | number, string | undefined>, Record<string, any>>' but required in type '{ respnse: any; }'.
route.get('/',async({

    at file:///D:/deno_mongo/src/routes/router.ts:5:15

    'respnse' is declared here.
        respnse : any;
        ~~~~~~~
        at file:///D:/deno_mongo/src/routes/router.ts:8:5

TS2339 [ERROR]: Property 'response' does not exist on type '{ respnse: any; }'.
    response
    ~~~~~~~~
    at file:///D:/deno_mongo/src/routes/router.ts:6:5

TS2345 [ERROR]: Argument of type '{ depth: number; sorted: boolean; trailingComma: boolean; compact: boolean; iterableLimit: number; }' is not assignable to parameter of type 'InspectOptions'.
  Object literal may only specify known properties, and 'sorted' does not exist in type 'InspectOptions'.
        sorted: true,
        ~~~~~~~~~~~~
    at https://deno.land/std@0.61.0/testing/asserts.ts:26:9

Found 3 errors.

这是我的 deno 版本。

deno 1.0.3
v8 8.4.300
typescript 3.9.2

如何解决这个错误?

您有一个错字:respnse : any; => response: any;

您可以使用 Response 而不是 any,这是实际类型。

import { Router, Response } from "https://deno.land/x/oak/mod.ts";

const route = new Router();

route.get('/',async({
    response
}: {
    response : Response; // Error here

}) => {
    response.status = 200;
    response.body = {
        message: "welcome"
    }
});

export default route;

@Gagantous:我碰巧遇到了同样的问题。我是 运行 deno 1.1.1 版本,但在 https://github.com/denoland/deno/issues/6780 问题跟踪中提到我们需要升级到 deno 1.2.0。我进行了强制升级以进行修复。之后它工作正常。

我遇到了同样的问题,我通过升级安装在我机器上的 deno 版本解决了这个问题,我的旧版本是 1.1.2 升级到最新版本后 1.2.0 这个问题解决了并且现在工作正常

看看这个问题deno