Skip to content

Instance of class exported via module.exports exports the class in generated type definition file #40019

@brucedjones

Description

@brucedjones

TypeScript Version: Nightly

Search Terms: export instance of class

Code

class Foo {
    
}

module.exports = new Foo();

Expected behavior:
.d.ts

declare const _exports: Foo;
export = _exports;
declare class Foo {
}

Actual behavior:
.d.ts

declare const _exports: typeof Foo;
export = _exports;
declare class Foo {
}

The consequence of this issue is that when I import the exported object from another package, typescript incorrectly treats the imported object as though it is the class and not an instance of the class.

Playground Link: https://www.typescriptlang.org/play?ts=4.0.0-dev.20200803&useJavaScript=true#code/MYGwhgzhAEBiD29oG8BQ0PVQX1agtvACYCuIApgHTkAeADvAE4AuMAvNAHbkDuciACgCUAbiA

Related Issues: None found

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: JavaScriptThe issue relates to JavaScript specificallyFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions