How can I export classes from Typescript factory functions?

169 views Asked by At

I'm working on an Angular/Typescript application that has been partially converted from Javascript (there are class definitions, but fields and variables are mostly untyped, and the style remains very js-like).

Many classes are defined inside factory functions like this:

export default function SomeClassFactory($http) {

    class SomeClass {

        constructor() {
            // initialise
        }

        someMethod($http) {
            // do something with $http
        }
    }

    return SomeClass;
}

It seems to be impossible to export inner classes defined in this way for use in import statements. I have tried moving the class declaration outside the factory function, but this fails when the class uses values that Angular injects, as in the example. (Presumably these injected values are effectively static members of the class.)

How can I export a class defined in this way?

0

There are 0 answers