microsoft / microsoft/TypeScript

Correct declaration emit of commonjs exports of namespace-nested classes

Open
#40,479 0 comments 0 reactions 1 assignee View on GitHub

@sandersn is already working on this.

Since Sep 10, 2020.

Bug Domain: Declaration Emit
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Followup to #40228:

var NS = {}
NS.K =class {
    values() {
        return new NS.K()
    }
}
exports.K = NS.K;

Expected behavior:

Should produce d.ts output:

declare namespace NS {
    class _K {
      values(): _K;
    }
    export {_K as K};
}
import _K = NS.K;
export {_K as K};

Actual behavior:

export var K: {
    new (): {
        values(): any;
    };
};
  1. Inlines and destroys the namespace.
  2. Only exports a value, not a class.
  3. Doesn't serialise nested typed references to K properly.

The declaration emitter just needs code to support this; right now it's hitting inaccurate fallback code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.