Skip to content

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

Closed

Description

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

Activity

  1. added
    Domain: Declaration Emit
    Domain: JavaScript
    on Aug 12, 2020
  2. added
    Fix Available
    on Aug 13, 2020
  3. changed the title [-]Instance of class is exported via module.exports exports the class in generated type definition file[/-] [+]Instance of class exported via module.exports exports the class in generated type definition file[/+] on Aug 14, 2020
  4. added
    Rescheduled
    and removed
    Rescheduled
    on Aug 31, 2020
  5. 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

BugDomain: Declaration EmitDomain: JavaScriptFix Available

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ Proxy