Skip to content

How to import one node_modules/@types and pin the reference to it like IncludeDeclarations works #848

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
presto41 opened this issue Aug 29, 2018 · 11 comments
Labels
help wanted Contributions are especially encouraged question Question about functionality

Comments

@presto41
Copy link

presto41 commented Aug 29, 2018

In my code is some function which return object which has of type from node_modules/@types.
I need to include this type because I need to show reference to this @type and I need to show this @type too. So I was trying those ways:

  1. added path to this type in 'src' statement, e.g.: '**/node_modules/@types/someType/index.d.ts'
  2. by set includeDeclarations as true

First way had been ignored. I thought at the first look that the second is working well but I observed something. I observed that the full of node_modules had been including into my documentation. But I don't need all of node_modules into my documentation. I need only this one type.

I'm so disappointed because without includeDeclarations my documentation cannot to find node_modules type but with it - is including a lot of redundant code.

Is any way to do it?

There are my typedoc configs.
First of them from point 1.:

typedoc: {
    build: {
        options: {
            module: 'commonjs',
            out: '../MyDocumentation/',
            name: 'MyApp',
            target: 'es5',
            exclude: [
                '**/folderA/*.d.ts',
                '**/folderB/*.d.ts'
            ],
            excludePrivate: true,
            externalPattern: "**/*/{fileX,fileY,fileZ}.ts",
            mode: 'file'
        },
        src: [
            'folderA/*.ts',
            'folderB/*.ts',
            **/node_modules/@types/someType/*.d.ts
        ]
    }
}   

Second from point 2:

typedoc: {
    build: {
        options: {
            module: 'commonjs',
            out: '../MyDocumentation/',
            name: 'MyApp',
            target: 'es5',
            exclude: [
            	'**/node_modules/**',
                '**/folderA/*.d.ts',
                '**/folderB/*.d.ts'
            ],
            includeDeclarations: true,
            excludePrivate: true,
            externalPattern: "**/*/{fileX,fileY,fileZ}.ts",
            mode: 'file'
        },
        src: [
            'folderA/*.ts',
            'folderB/*.ts',
        ]
    }
}        

I'm looking for a way how to include my @type but without a rest of node_modules.

@presto41 presto41 changed the title Problem with documentation while includeDeclarations is set to true IncludeDeclarations = true is importing a lot of redundant code Aug 29, 2018
@aciccarello aciccarello added help wanted Contributions are especially encouraged question Question about functionality labels Aug 29, 2018
@presto41 presto41 changed the title IncludeDeclarations = true is importing a lot of redundant code How to import one node_modules/@types and pin the reference to it like IncludeDeclarations works Sep 3, 2018
@aciccarello
Copy link
Collaborator

See also: Stack Overflow question

@presto41
Copy link
Author

presto41 commented Sep 3, 2018

@aciccarello it is my question too. I was asking at StackOverflow too when I saw that there is not reply from a long time

@presto41 presto41 reopened this Oct 15, 2018
@bbert
Copy link

bbert commented Jun 6, 2019

Hi @presto41, have you find a solution to this issue. I have the same request; i.e. including types from an imported package from node_modules

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 7, 2019

There isn't a nice solution to this yet. If you don't have too many @types packages installed, you could create an exclude pattern for ones you don't want in your config file

{
  "exclude": [ "**/\\@types/{foo,bar}/index.d.ts" ]
}

@bbert
Copy link

bbert commented Jun 7, 2019

ok thanks, but in my case I wanted to include types from a package that do not have published types (in @types folder)

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 7, 2019

That should make it easier, just exclude the @types folder.

@mrestorff
Copy link

Has there been an update on this?
I'm trying to include multiple node modules that have type declarations I want to use.
This isn't working:
{ "inputFiles": [ "./src", "./node_modules/botbuilder/src", "./node_modules/botbuilder-ai/src", "./node_modules/botbuilder-applicationinsights/src", "./node_modules/botbuilder-azure/src", "./node_modules/botbuilder-core/src", "./node_modules/botbuilder-dialogs/src", "./node_modules/botbuilder-lg/src", "./node_modules/botbuilder-testing/src", "./node_modules/botframework-schema/src" ] }

It would be a great feature to be able to include certain paths without having to exclude all the other node modules.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented May 17, 2020

I believe you should be able to do something like this (untested, but a similar pattern worked when I was checking another issue)

{
  "inputFiles": [ "./src", "./node_modules/botbuilder/src" ],
  "includeDeclarations": true,
  "excludeExternals": true
}

@mrestorff
Copy link

mrestorff commented May 17, 2020

Thanks for getting back to me!

I tried exactly that but it did not solve the issue. However, using the CLI to specify multiple inputFiles did work as expected: typedoc --inputFiles "./src" --inputFiles "./node_modules/botbuilder/src"

My config file currently looks like this:

{
    "inputFiles": [
        "./src",
        "./node_modules/botbuilder/src",
    ],
    "exclude": "**/*.test.ts",
    "includeDeclarations": true,
    "excludeExternals": true,
    "mode": "file",
    "target": "es6"
}

I'm simply using the typedoc command in CLI without any parameters.

Provided there is nothing wrong with my typedoc.json, this looks like a bug to me.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented May 17, 2020

I think that's the same issue as #1263, there's a fix but since it requires bumping the minimum node version it can't be merged until 0.18. I hope to get a lot closer to that release today/this week.

Alternative workaround: add a typedocOptions key in tsconfig.json and specify inputFiles there.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 28, 2020

TypeDoc 0.20 will now document whatever you export - if that's from your dependencies, that's fine. If not, that's fine too. If not exported, it won't be documented.

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

No branches or pull requests

5 participants