Skip to content

Classes and constructor functions are not exported as types in js files #24064

Closed

Description

TypeScript Version: 2.9.0-dev.201xxxxx

Search Terms:

Code

// b.js

function F() {
    this.prop = 0;
}

class C {
    prop = 0;
}

exports.F = F;
exports.C = C;
// a.js

/** @type {import("./b").C} */
var x;
x.  // expect 'prop' to show in the list


/** @type {import("./b").F} */
var y;
y.  // expect 'prop' to show in the list

Expected behavior:

both x and y should have prop in their completion list

Actual behavior:

No completions

Related Issues:

I would also expect this to be have the same way:

// b.js 

function F() {
    this.prop = 0;
}

class C {
    prop = 0;
}

module.exports = {
    F,
    C
}

Activity

  1. sandersn commented on Aug 23, 2018

    @sandersn
    Member

    The first repro now works, but the second one with module.exports = { F, C } still doesn't.

    Edit: It's probably because we treat the former similarly to the typescript export class C { prop = 0 }; and the latter similarly to export = { F, C }, which also doesn't work with import types. That's a separate issue.

  2. joma74 commented on Sep 1, 2018

    @joma74

    TS 3.1.0-dev.20180901 here.

    The following works.

    // step.js
    module.exports.Step = Step;
    
    // task.js
    /**
     * @typedef {import ("./step").Step} Step
     */
    

    But writing here as the following may be covered here alike, but is currently not. Or should i open another issue?

    // step.js
    module.exports = Step;
    
    // task.js
    /**
     * @typedef {import ("./step").default} Step
     */
    
  3. joma74 commented on Sep 1, 2018

    @joma74

    My bad. In my second case, this works and is sufficient

    // task.js
    /**
     * @typedef {import ("./step")} Step
     */
    
  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions