Skip to content

JSDoc does not pick up type imported from foreign modules using require #19678

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
KtorZ opened this issue Nov 2, 2017 · 2 comments
Closed

JSDoc does not pick up type imported from foreign modules using require #19678

KtorZ opened this issue Nov 2, 2017 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@KtorZ
Copy link

KtorZ commented Nov 2, 2017

In the lights of #14056, the import of type defined by Classes seems to work fine from within a module (using local imports) but does not go beyond it. Therefore, where the following example works fine:

TypeScript Versions: 2.7.0-dev.20171102, 2.6.1

Code

module: A, file: a.js

class Action { /* whatever */ }

module.exports = Action;

module: A, file: b.js

const Action = require('./a');

/**
 * @param {Action} arg 
 */
function foo(arg) { /* whatever */ }

Here the type is picked up correctly in b.js and typescript works like a charm. However, if A is used as an installed dependency from another module:

module B, file c.js

const Action = require('A/a');

/**
 * @param {Action} arg
 */
function bar(arg) { /* whatever */ }

Actual behavior:

Typescript complains with the following:

error TS2304: Cannot find name 'Action'.

Expected behavior:

Is this an intended behavior or, should the type also be picked up? I don't see how and why using a module as a dependency should remove the initial behavior.

Thanks for the help 👍

@ghost
Copy link

ghost commented Nov 2, 2017

When it's from node_modules we probably aren't checking it at all, thus Action would just be a variable of type any. (You probably don't have --noImplicitAny set.)
Ideally the package A would have something on DefinitelyTyped to provide types.
You could also try increasing --maxNodeModuleJsDepth to pick up those files into the project, although that can slow build times.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 2, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants