cmorten / superoak

HTTP assertions for Oak made easy via SuperDeno. 🐿 🦕
https://cmorten.github.io/superoak/
MIT License
121 stars 8 forks source link

error: TS2345 [ERROR]: Argument of type 'Application<Record<string, any>>' is not assignable to parameter of type 'string | Application<Record<string, any>>'. #1

Closed Leonardo-Rocha closed 4 years ago

Leonardo-Rocha commented 4 years ago

Issue

Setup:

deno 1.0.3 v8 8.4.300 typescript 3.9.2

const router = new Router();
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

const response: SuperDeno = await superoak(app);

Running this code gives me:

Details

error: TS2345 [ERROR]: Argument of type 'Application<Record<string, any>>' is not assignable to parameter of type 'string | Application<Record<string, any>>'.
  Type 'import("https://deno.land/x/oak/application").Application<Record<string, any>>' is not assignable to type 'import("https://deno.land/x/oak@v5.0.0/application").Application<Record<string, any>>'.
    Property '#middleware' in type 'Application' refers to a different member that cannot be accessed from within type 'Application'.
    const response: SuperDeno = await superoak(app);
asos-craigmorten commented 4 years ago

@Leonardo-Rocha can you confirm the version/branch/commit you are using in your app to import Oak?

I'm guessing I might have coupled SuperOak too tightly to a specific Oak version (v5.0.0) which is destined to fail as Oak progresses (without a lot of work) and would not be scalable for backwards compatibility - I'll look to loosen the types this morning and get a patch out.

asos-craigmorten commented 4 years ago

I can confirm the issue exists and reproduced with:

import { Router, Application } from "https://deno.land/x/oak@master/mod.ts";
import { superoak, SuperDeno } from "https://deno.land/x/superoak@master/mod.ts";

const router = new Router();
const app = new Application();

router.get("/", (ctx) => {
  ctx.response.body = "Hello Deno!";
});

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

const request: SuperDeno = await superoak(app);

request.get("/").end((err) => {
  if (err) throw err;
});

With error:

error: TS2345 [ERROR]: Argument of type 'Application<Record<string, any>>' is not assignable to parameter of type 'string | Application<Record<string, any>>'.
  Type 'import("https://deno.land/x/oak@master/application").Application<Record<string, any>>' is not assignable to type 'import("https://deno.land/x/oak@v5.0.0/application").Application<Record<string, any>>'.
    Property '#middleware' in type 'Application' refers to a different member that cannot be accessed from within type 'Application'.
const request: SuperDeno = await superoak(app);
asos-craigmorten commented 4 years ago

Fixed in #2

Have re-tested with above snippet and works as expected. Please re-open if the issue persists.

Note: you will need to update to 1.0.1 of SuperOak, or if you are using master for versioning your import, you may need to pass a --reload flag to pull down the latest and break the existing Deno cache.

Leonardo-Rocha commented 4 years ago

@asos-craigmorten It looks like it's working now. Thanks Craig!