0

I have following modules in my app:

In Loader.ts:

module Loader {

    export default class FLoader {

        constructor () {}

        // blahblahblah...

    }
}

In Renderer.ts:

import Loader from "../Loader";

module Renderer {

    export default class FRenderer {

        constructor () {}

        public SomeFunction(): void {

            let myLoader = new Loader(); // error: Cannot use 'new' with an expression whose type lacks a call or construct signature

        }

    }
}

And I get error noted in the code: Cannot use 'new' with an expression whose type lacks a call or construct signature

I'm following the docs here. What am I doing wrong?

1
  • 1
    You are trying to instantiate Loader which is a module instead of FLoader which is a class. A module can't not be instantiated. Commented Sep 5, 2016 at 10:31

1 Answer 1

1

I think that it should be:

export module Loader {
    export class FLoader {
        constructor () {}

        // blahblahblah...
    }
}

And then:

import * as Loader from "./Loader";

let myLoader = new Loader.FLoader();

At least that works for me.


Edit

As @JimW commented, this code won't work, it should be used like this:

let myLoader = new Loader.Loader.FLoader();

To make it work it should be:

// Loader.ts
export class FLoader {
    constructor () {}

    // blahblahblah...
}

And then importing it:

import * as Loader from "./Loader";
let myLoader = new Loader.FLoader();

There's no need to create a module for Loader, as it happens already just by using a different file for it.

Sign up to request clarification or add additional context in comments.

3 Comments

Any idea why in Visual Studio Code I have to do let myLoader = new Loader.Loader.FLoader(); when using your example?
@JimW Right, check my revised answer
Thanks, I get it now the as XXXX in the import is the namespace/module name that it is imported as.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.