1
votes

I am having issue with this error Ts2345 while using docker run. any suggestions please?

error: 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

My test.ts

import {filterHabitablePlanets} from "./planets.ts";

const HABITABLE_PLANET ={
    koi_disposition: "CONFIRMED", 
    koi_prad: "1",
    koi_srad: "1",
    koi_smass: "1",
};

const NOT_CONFIRMED ={
    koi_disposition: "FALSE POSITIVE", 
  
};

const TOO_LARGE_PLANETARY_RADIUS ={
    koi_disposition: "CONFIRMED", 
    koi_prad: "1.5",
    koi_srad: "1",
    koi_smass: "1",
};

const TOO_LARGE_SOLAR_RADIUS ={
    koi_disposition: "CONFIRMED", 
    koi_prad: "1",
    koi_srad: "1.01",
    koi_smass: "1",
};

const TOO_LARGE_SOLAR_MASS ={
    koi_disposition: "CONFIRMED", 
    koi_prad: "1",
    koi_srad: "1",
    koi_smass: "1.04",
};




Deno.test("filter only habitable planets", () =>{
   const filtered = filterHabitablePlanets ([
        HABITABLE_PLANET,
        NOT_CONFIRMED,
        TOO_LARGE_PLANETARY_RADIUS,
        TOO_LARGE_SOLAR_RADIUS,
        TOO_LARGE_SOLAR_MASS,
    ]);

    assertEquals ( filtered, [
        HABITABLE_PLANET,
    ]);
});

api.ts file


import { Router } from "../src/deps.ts";

import * as planets from "../models/planets.ts";
import * as launches from "../models/launches.ts";

const router = new Router();

router.get("/", (ctx) => {
  ctx.response.body = "Response-server";
});

router.get("/planets", (ctx) => {
  ctx.response.body = planets.getAll();
});

router.get("/launches", (ctx) => {
  ctx.response.body = launches.getAll();
});

router.get("/launches/:id", (ctx) => {
  if (ctx.params?.id) {
    const launchData = launches.getOne(Number(ctx.params.id));
    if (launchData) {
      ctx.response.body = launchData;
    } else {
      ctx.throw(400, "Launch with that ID doesn't exist");
    }
  }
});

router.delete("/launches/:id", (ctx) => {
  if (ctx.params?.id) {
    const result = launches.removeOne(Number(ctx.params.id));
    ctx.response.body = { success: result };
  }
});

router.post("/launches", async (ctx) => {
  const body = await ctx.request.body();

  launches.addOne(body.value);

  ctx.response.body = { success: true };
  ctx.response.status = 201;
});

export default router;

mod.ts file


import api from "../src/api.ts";
import { log, Application, send } from "../src/deps.ts";

const app = new Application();
const PORT = 3000;

await log.setup({
    handlers: {
      console: new log.handlers.ConsoleHandler("INFO"),
    },
    loggers: {
      default: {
        level: "INFO",
        handlers: ["console"],
      },
    },
  });
  

app.addEventListener("error", (event) => {
    log.error(event.error);
});


// error handling

app.use(async(ctx, next) =>{
    try{
        await next();
    } catch(err){
    
        ctx.response.body="Internal server error";
        throw err;
    }
    
});

app.use(async(ctx, next) => {
    await next();
    const time = ctx.response.headers.get("X-Response-Time")
    log.info(`${ctx.request.method} ${ctx.request.url}: ${time}`);
});


app.use(async(ctx, next) => {
    const start = Date.now();
    await next();
    const delta = Date.now() - start;
    ctx.response.headers.set("X-Response-Time", `${delta}ms`);
});

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

app.use(async(ctx) => {
    const filePath = ctx.request.url.pathname;
    const fileWhitelist = [ 
        "/index.html",
        "/javascripts/script.js",
        "/stylesheets/style.css",
        "/images/flavicon.png",
        "/videos/space.mp4",
    ];
// important for security reasons
    if (fileWhitelist.includes(filePath)){
        await send(ctx, filePath, {
            root: `${Deno.cwd()}/public`, 
        });
    }
    
});


    
if (import.meta.main){
    log.info(`Starting server on port ${PORT}...`);
    await app.listen({
        port: PORT
    });  
}

1

1 Answers

1
votes

Try upgrading Deno to a newer version. The version of oak you are using may not be compatible with earlier versions of Deno

See: https://github.com/denoland/deno/issues/6780