Skip to content

TypeDoc doesn't support the lib option #315

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
kayahr opened this issue Oct 23, 2016 · 14 comments · Fixed by #449
Closed

TypeDoc doesn't support the lib option #315

kayahr opened this issue Oct 23, 2016 · 14 comments · Fixed by #449

Comments

@kayahr
Copy link

kayahr commented Oct 23, 2016

I use the new lib option in tsconfig.json to explicitly set the built-in type definitions I want to use in my project:

{
    "$schema": "http://json.schemastore.org/tsconfig",
    "compilerOptions": {
        "target": "es5",
        "lib": [ "es2015.promise", "es2015.core", "es2015.collection", "es5", "dom" ],
        "module": "commonjs",
        "rootDir": "src",
        "outDir": "lib",
        "noEmitOnError": true,
        "sourceMap": true,
        "declaration": true,
    },
    "exclude": [
        "node_modules",
        "lib"
    ]
}

Unfortunately typedoc doesn't support this:

$ typedoc --out doc src
Error: Unknown option `lib.0`.
Error: Unknown option `lib.1`.
Error: Unknown option `lib.2`.
Error: Unknown option `lib.3`.
Error: Unknown option `lib.4`.

For now I reverted back to using external type definitions for the needed ES2015 features so I'm able to use TypeDoc but it would be nice if TypeDoc could support this useful new feature.

@aciccarello
Copy link
Collaborator

This is a remaining issues following #234. PR #308 ignored this option to allow TypeDoc to run but PRs to enable lib support are very welcome.

@unsafecode
Copy link

@aciccarello Any ETA on a fixing release? I cannot run typedoc anymore on TS 2.0

@aciccarello
Copy link
Collaborator

@unsafecode As far as I know no one is working on it. There is no active maintainer of this project so fixes/features are entirely community driven.

@jonaskello
Copy link

jonaskello commented Oct 28, 2016

It seems the fix has been merged but there is no new release. I tried to install from master branch to get it:

npm install -g https://github.com/TypeStrong/typedoc.git#master

Installing works but running does not:

$ typedoc
module.js:457
    throw err;
    ^

Error: Cannot find module '../lib/cli.js'
    at Function.Module._resolveFilename (module.js:455:15)

@kayahr
Copy link
Author

kayahr commented Nov 28, 2016

Since typedoc 0.5.1 the "lib" option is silently ignored and typedoc now complains about the missing type definitions. I found a simple but ugly workaround (No pull request for this) to fix this (At least for me). Insert these lines into bin/typedoc so the lib settings are converted to command line parameters (Directly referencing the .d.ts files of typescript):

var path = require("path");
var tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
var tsconfig = require(tsconfigPath);
if (tsconfig.compilerOptions && tsconfig.compilerOptions.lib) {
    tsconfig.compilerOptions.lib.forEach(function(lib) {
        process.argv.push("node_modules/typescript/lib/lib." + lib + ".d.ts");
    });
}

As I said this is just an ugly "works for me" workaround and I just mention it in case it is useful for someone else waiting for a real fix for this issue.

@aciccarello
Copy link
Collaborator

Does anyone know if this was fixed in #359?

@nakedcity
Copy link

nakedcity commented Jan 16, 2017

Any update on this one ??? lib is not taken in account yet, why this is not assigned to anyone?

@bafolts
Copy link

bafolts commented Mar 13, 2017

You can also manually include the lib files in your include section of your typescript config file. A less hackier version than modifying the binary.

    "include": [
        "../node_modules/typedoc/node_modules/typescript/lib/lib.dom.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es5.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.core.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.collection.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.reflect.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.iterable.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.promise.d.ts",
        "../node_modules/typedoc/node_modules/typescript/lib/lib.es2015.symbol.d.ts",

nicknisi added a commit to nicknisi/typedoc that referenced this issue Mar 15, 2017
* Remove restriction on what compilerOptions can be set
* remove filtering of TS 2.2 compilerOptions
* add support for 'list' option types
* Switch to processed compilerOptions
* add support for `compilerOptions.lib`

This PR removes the restrictions on setting options that aren't explicitly setup as options to allow new compilerOptions
to pass through TypeDoc to TypeScript. It also sets up support for 'list' parameter types, and switches to use the
processed compilerOptions, rather than `raw` so that the `lib` properties are properly parsed.

This should fix TypeStrong#315 and I believe TypeStrong#311.
nicknisi added a commit to nicknisi/typedoc that referenced this issue Mar 15, 2017
* Remove restriction on what compilerOptions can be set
* remove filtering of TS 2.2 compilerOptions
* add support for 'list' option types
* Switch to processed compilerOptions
* add support for `compilerOptions.lib`

This PR removes the restrictions on setting options that aren't explicitly setup as options to allow new compilerOptions
to pass through TypeDoc to TypeScript. It also sets up support for 'list' parameter types, and switches to use the
processed compilerOptions, rather than `raw` so that the `lib` properties are properly parsed.

This should fix TypeStrong#315 and I believe TypeStrong#311.
nicknisi added a commit to nicknisi/typedoc that referenced this issue Mar 22, 2017
* Remove restriction on what compilerOptions can be set
* remove filtering of TS 2.2 compilerOptions
* add support for 'list' option types
* Switch to processed compilerOptions
* add support for `compilerOptions.lib`

This PR removes the restrictions on setting options that aren't explicitly setup as options to allow new compilerOptions
to pass through TypeDoc to TypeScript. It also sets up support for 'list' parameter types, and switches to use the
processed compilerOptions, rather than `raw` so that the `lib` properties are properly parsed.

This should fix TypeStrong#315 and I believe TypeStrong#311.
@yohei1126
Copy link

yohei1126 commented Mar 22, 2017 via email

@brphelps
Copy link

@blakeembrey , @nicknisi -- Is the lib option (specifically) supported via any command line args? Gulp-typedoc is basically a passthrough for command line options, and while I'm using lib in my tsconfig, I'm not sure if I can pipe that into that plugin anymore.

@nicknisi
Copy link
Collaborator

nicknisi commented Apr 2, 2017

@brphelps It's not specifically supported via the command line currently, but it is something that should probably be supported. When set via command line args, it does pass through to TypeScript, but it doesn't get the conversion to the correct filename. Currently, typedoc --lib dom,es2015 passes to TypeScript as ['dom', 'es2015'], but it should be passed as ['lib.dom.d.ts, 'lib.es2015.d.ts'].

@nicknisi nicknisi reopened this Apr 2, 2017
@iburton
Copy link

iburton commented Mar 16, 2018

FYI, this seems to work for my project, not sure if it is universal or not:
lib: ["lib.dom.d.ts", "lib.es2015.d.ts"],

@aciccarello
Copy link
Collaborator

When using tsconfig.json the shorthand lib: ['es2015'] options are parsed correctly. However, as @nicknisi noted, the CLI arguments are not parsed correctly and the lib d.ts files are not found. The simplest solution would be to have TypeDoc map the lib options to their declaration files. However, a better solution would be to defer to TypeScript's mapping of lib options.

A workaround for this issue is to use the full declaration file name (e.g. --lib lib.es2015.d.ts) when passing lib options via the command line.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 16, 2020

Passing TS options (like lib) through the command line should not be required in the vast majority of cases. We support reading a tsconfig.json file, which is where TS options should really be set.

I'm not worried about requiring the full declaration file name on the command line. In the 100 or so projects that I've looked at that use TypeDoc, none pass lib options through the CLI. I don't think the extra complexity in the option parsing code to handle shorthand names is worth it.

@Gerrit0 Gerrit0 closed this as completed Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.