Search code examples
typedoc

TypeDoc fails with static block


TypeDoc does not understand TypeScript static blocks. Static blocks were added to TypeScript 4.4. I am using TypeDoc 0.22.17 which claims to support TypeScript versions 4.0 through 4.7 https://typedoc.org/guides/installation/

Is there something else I need to do to make TypeDoc understand static blocks in TypeScript?


For example of problem, here is file "src/hello.js":

/**
 * My class
 */
export class HelloWorld {
    constructor() {
        console.log("Hello World");
    }

    static {
        new HelloWorld();
    }
}

... and "tsconfig.json":

      {
        "compilerOptions": {
          "module": "ES2020",
          "target": "ES6",
          "sourceMap": true,
          "outDir": "build",
        },
        "include": [
          "src/**/*"
        ],
      }

When I run "npx typedoc -out html src/hello.ts" I get the following error messages:

Error: src/hello.ts:9:11 - error TS1146: Declaration expected.

9     static {
            

Error: src/hello.ts:9:12 - error TS1005: ';' expected.

9     static {
             ~

Error: src/hello.ts:12:1 - error TS1128: Declaration or statement expected.

12 }

Solution

  • As Gerrit0 wrote, you need to check the version of TypeDoc is as expected and TypeDoc's version of TypeScript is as expected too. The command "npx typedoc --version" prints both versions.