Skip to content

Using TypeDoc with projects that include JavaScript? #643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dtgriscom opened this issue Nov 6, 2017 · 7 comments
Closed

Using TypeDoc with projects that include JavaScript? #643

dtgriscom opened this issue Nov 6, 2017 · 7 comments
Labels
question Question about functionality

Comments

@dtgriscom
Copy link

I'm working on a project where the shell is standard JavaScript, but most of the core code is written using TypeScript. Will TypeDoc work in such a situation?

I guess there are a number of levels of "working":

  1. TypeDoc will tolerate JavaScript files that it encounters, but won't generate documentation for them

  2. TypeDoc will parse JavaDoc comments in JavaScript files and add them to the documentation tree

  3. TypeDoc will read JavaScript files, parse JavaDoc comments, and in addition figure out what it can from the symbols and argument lists, and add it all to the documentation tree

Will TypeDoc do any of this?

Thanks,
Dan

@aciccarello
Copy link
Collaborator

@dtgriscom TypeDoc gets the type information from the TypeScript compiler so the things that the compiler understands will get passed to TypeDoc. That said, I haven't tried parsing JavaScript myself so I'm not sure what level of support exists. Let us know how things work for you!

@aciccarello aciccarello added the question Question about functionality label Nov 6, 2017
@dtgriscom
Copy link
Author

dtgriscom commented Nov 6, 2017

No go:

Error: File '/Users/griscom/Documents/project/arguments.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.

Such is life...
Dan

@dtinth
Copy link

dtinth commented Dec 25, 2017

It works fine but you need to configure the TypeScript compiler:

typedoc --allowJs --ignoreCompilerErrors --module commonjs --out /tmp/bms-js-docs ~/Bemuse/bms-js/index.js
  • --allowJs Makes TypeScript not bail when it found .js file extension.
  • --ignoreCompilerErrors Is needed because compiling JS file as TypeScript will likely cause the compiler to complain.
  • --module commonjs Is needed if you want TypeDoc to parse require() calls.

@Manleen
Copy link

Manleen commented Feb 16, 2018

I'm using the above command still it doesn't generates documentation for *.js files.
Any idea why --allowJs is not working?

@aciccarello
Copy link
Collaborator

@Manleen Can you link to a repo where we could see your code and error?

@Manleen
Copy link

Manleen commented Feb 16, 2018

I don't see any error. I have both .ts and .js files in the source code. When I use typedoc to generate the documentation, it just generates docs for ts files. The repo is private so I can't link it.

@eternalphane
Copy link

eternalphane commented Apr 20, 2018

@Manleen You should define typedoc options in tsconfig.json and use --tsconfig option to load the file. Here's an example:

tsconfig.json

{
    "compilerOptions": {
        "allowJs": true,
        "module": "es2015",
        "target": "es6"
    },
    "include": [
        "src/**/*.js"
    ],
    "typedocOptions": {
        "ignoreCompilerErrors": true,
        "mode": "modules",
        "out": "./docs"
    }
}

and then

> typedoc --tsconfig tsconfig.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about functionality
Projects
None yet
Development

No branches or pull requests

5 participants