How to make typedoc works with deno

475 views Asked by At

I am using Deno in one of my projects and I want to generate the documentation with typedoc. I am facing a lot of problems with dependencies because they do not get resolved correctly, so typedoc fails. I have the following tsconfig.json:

{
  "compilerOptions": {
    "module": "amd",
    "target": "esnext",
    "baseUrl": ".",
    "paths": {
      "http://*": ["../../../.deno/deps/http/*"],
      "https://*": ["../../../.deno/deps/https/*"],
      "*.ts": ["*"]
    },
    "plugins": [
      {
        "name": "typescript-deno-plugin"
      }
    ]
  }
}

The first two entries in paths resolve the native modules of Deno (like its assertion library). The problem comes when I use another library like Cheerio, importing it like this in my deps.ts file:

// @deno-types="https://cdn.jsdelivr.net/gh/justjavac/deno_cheerio/cheerio.d.ts"
import cheerio from "https://dev.jspm.io/cheerio/index";

Note: I have to import the types from an external source because the types declared in dev.jspm.io do not work because they include the /// reference directive.

I have the following typedoc.js config file:

// deno-lint-ignore-file
module.exports = {
  out: "./docs-build",
  mode: "file",
};

If I run typedoc src/, I get the following error:

Using TypeScript 4.0.3 from /home/antonio/.nvm/versions/node/v12.18.1/lib/node_modules/typescript/lib
Error: /home/antonio/manga-api/src/deps.ts(8)
 Cannot find module 'https://dev.jspm.io/cheerio/index'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

Note2: I'm using deno but typedoc is installed with npm globally, along typescript and typescript-deno-plugin.

Any idea how to make typedoc work correctly with Deno?

2

There are 2 answers

0
jordanbtucker On BEST ANSWER

I was able to get TypeDoc working (at least with a simple library) by performing these steps.

Output Deno's types so TypeDoc can find them.

deno types > deno.d.ts

Add a tsconfig.json file based on Deno's implied tsconfig.json file, then remove lib and set allowImportingTsExtensions.

{
  "compilerOptions": {
    "allowImportingTsExtensions": true,
    "allowJs": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "inlineSourceMap": true,
    "isolatedModules": true,
    "jsx": "react",
    "module": "esnext",
    "moduleDetection": "force",
    "strict": true,
    "target": "esnext",
    "useDefineForClassFields": true
  }
}

Add a typedoc.json file with entryPoints and skipErrorChecking set.

{
  "entryPoints": ["./mod.ts"],
  "skipErrorChecking": true
}

Alternatively run TypeDoc with with the --skipErrorChecking flag and provide the entry points.

typedoc --skipErrorChecking ./mod.ts

This worked with the following versions:

  • Deno: 1.36.1
  • TypeDoc: 0.25.0
3
Steven Guerrero On

Typedoc won't work with Deno. Deno supports module resolution and URL resolution, which Node (the current runtime for Typedoc) lacks of. The only way it could work is if Typedoc itself run in Deno, but it doesn't offer support for it at the moment.