denooak

Deno and oak error: TS2315 [ERROR]: Type 'Conn' is not generic - with Deno using oak as server on macOs with basic example code


I am trying out Deno with oak and I am running into the same error everytime - even when I try the default example. My working environment is macOs Big Sur. Does anybody know how to fix this issue?

$ deno run --allow-net server.ts 
Check file:///.../server.ts
error: TS2315 [ERROR]: Type 'Conn' is not generic.
export function isConn(value: unknown): value is Deno.Conn<Deno.NetAddr> {
                                                 ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/util.ts:66:50

TS2315 [ERROR]: Type 'Conn' is not generic.
  #conn?: Deno.Conn<Deno.NetAddr>;
          ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/http_server_native.ts:41:11

TS2315 [ERROR]: Type 'Conn' is not generic.
  constructor(requestEvent: RequestEvent, conn?: Deno.Conn<Deno.NetAddr>) {
                                                 ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/http_server_native.ts:49:50

TS2315 [ERROR]: Type 'Conn' is not generic.
        async function serve(conn: Deno.Conn<Deno.NetAddr>) {
                                   ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/http_server_native.ts:149:36

TS2315 [ERROR]: Type 'Conn' is not generic.
    conn?: Deno.Conn<Deno.NetAddr>,
           ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/application.ts:50:12

TS2315 [ERROR]: Type 'Conn' is not generic.
    secureOrConn: Deno.Conn<Deno.NetAddr> | boolean | undefined,
                  ~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/oak@v7.2.0/application.ts:374:19

Found 6 errors.

The sample code comes from here (https://github.com/oakserver/oak) and looks like this:

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

const app = new Application();

app.use((ctx) => {
    ctx.response.body = "Hello World!";
});

await app.listen({ port: 8000 });

Thank you!


Solution

  • The error comes from incompatibility between deno earlier than 1.9 and oak later than v7.

    Since I installed deno a few hours ago I was not checking the versions. With homebrew I got an older version - now I used

    curl -fsSL https://deno.land/x/install/install.sh | sh 
    

    instead.