Skip to content

File import ignored if the file containing the import statement doesn't explicitely reference a class deifined in the file #5098

Closed
@PezzerDev

Description

@PezzerDev

Class MyClass is defined in my-class.ts. The class is decorated with a custom decorator. The result of the decorator is some logic that will eventually cause MyClass to be instantiated.

Another file, other-file.ts, imports my-class.ts with:

import 'my-class';

other-file.ts has no explicit reference to MyClass, as it will automatically be instantiated and used as needed as a result of its decorator.

This works fine, until I try to import an interface, exported by my-class.ts

If I change the import within other-file.ts to:

import {ISomeInterface} from 'my-class'`;

I can now reference ISomeInterface within other-file.ts, but now the contents of my-class.ts is never actually compiled.

I suspect this is due to some optimization by the Typescript compiler. In general it would make sense that if nothing but interfaces were referenced from a class, there's no reason to generate javascript for it; however, the use of decorators makes that assumption erroneous.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions