Skip to content

Cannot import properties from module.exports as types in JSDoc #29485

@jordanbtucker

Description

@jordanbtucker

TypeScript Version: 3.3.0-dev.20190118

Search Terms: jsdoc import module.exports has no exported member

Code

a.js

class A {}

module.exports = {A}

b.js

// @ts-check
class B {
	// In the JSDoc below, VSCode intellisense does not recognize parameter a as type A.
    // Instead it shows the error:
    //   Namespace '".../a".export=' has no exported member 'A'

	/**
	 * @param {import('./a').A} a
	 */
	constructor (a) {
		this.a = a
	}
}

Expected behavior
Parameter a of the constructor should be recognized as type A, which is accessible via the A property of module.exports from a.js.

Actual behavior
Intellisense reports the error: Namespace '".../a".export=' has no exported member 'A'.

Notes
@param {import('./a')} a does not give an error, but it resolves to type {A: typeof A} instead of A.

If a.js is modified with module.exports = A, then import('./a') resolves to A, however this restricts a.js to only exporting one type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specifically

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions