Gagantous
Gagantous

Reputation: 518

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

This is my first time using Deno, i learn it from youtube and documentation. First thing i want to amke was make a simple local server using deno using this script.

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;

And this is my 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})

I run server.ts with this command

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

But i got this error while compile the data

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/[email protected]/testing/asserts.ts:26:9

Found 3 errors.

Here is my deno version.

deno 1.0.3
v8 8.4.300
typescript 3.9.2

How to solve this error ?

Upvotes: 1

Views: 633

Answers (3)

Ahmed Mahmoud
Ahmed Mahmoud

Reputation: 1832

I have faced the same problem and i resolved it by upgrading the version of deno that installed on my machine my old version was 1.1.2 after upgrading version to latest one 1.2.0 this issue resolved and it's working fine now

Just take a look about this issue deno

Upvotes: 1

vasanthraj devaraju
vasanthraj devaraju

Reputation: 148

@Gagantous: I took happened to witness the same issue. I was running with deno 1.1.1 version, but in https://github.com/denoland/deno/issues/6780, issue track it has been mentioned like we need to upgrade to deno 1.2.0. I did the force upgrade to make the fix. After that it is working fine.

enter image description here

Upvotes: 1

Marcos Casagrande
Marcos Casagrande

Reputation: 40434

You have a typo: respnse : any; => response: any;

Instead of any you can use Response instead which is the actual type.

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;

Upvotes: 1

Related Questions