How can I return a class from a TypeScript function?

I’m using TypeScript with a dependency injection library which works very similar to Angular 1 – basically: register a factory with your dependencies as arguments.

This is how I would register a class in ES6

export let factory = () => {
    return class Foo {}
};

If I write the same in TypeScript:

export let factory = () => {
    return class Foo {}
};

It fails to compile with the error

error TS4025: Exported variable ‘factory’ has or is using private name ‘Foo’.

Is there any way to allow TypeScript to return a class from a factory function?

31 thoughts on “How can I return a class from a TypeScript function?”

  1. 732864 103884I havent checked in here for some time because I thought it was getting boring, but the last couple of posts are really great quality so I guess Ill add you back to my daily bloglist. You deserve it my friend. insurance guides 662433

    Reply
  2. 449448 795329Informative Site Hello guys here are some links that contains information which you might find helpful yourselves. It is Worth Checking out. 756994

    Reply

Leave a Comment