0

This is the code in file- app.ts

  import Express = require('express');
  import FileSystem = require('fs');
  import Http = require('http');

module Service {
    export interface Configuration {
        Port: number,
        Host: string
    }
    export class AppServer {
        App: Express.Application;
        AppServer: Http.Server;

        constructor() {
            this.App = Express();
            this.App.use(this.App.route);
            // this.App.use(this.App.router);

        }

        /**
         * Start the server
         * @param {Configuration} config
         */
        StartServer = function (config: Configuration) {
            var That = this;
            this.AppServer = this.App.listen(config.Port, function () {

                var Host = That.AppServer.address().address;
                var Port = That.AppServer.address().port;

                console.log("Example app listening at http://%s:%s", Host, Port)

            })
        }
    }
}

when i am accessing the namespace in another file, i am getting the compile error that "unable to find service".

this is the code in file -server.ts

/// <reference path="App.ts" />

var Server = new Service.AppServer();
var Config = <Service.Configuration>{
    Port: 3000
}
Server.StartServer(Config);

but when i am removing the import statement which is requiring http and express, i am no more getting the error in the file. Please help me to find- where i am doing wrong?

the error i am gettinf is - 'ts2304' can not find name 'service'.

3
  • 1
    Could you quote the error message? Commented Dec 30, 2016 at 4:22
  • As per error which service you are not able to find ? is it for your Service module or for express, fs or http? Commented Dec 30, 2016 at 5:17
  • I have updated the question,btw the error i am getting is- 'ts2304' can not find name 'Service'. Commented Dec 30, 2016 at 7:45

1 Answer 1

2

It seems like you have not exported the module. Try adding export {Service} at the end of your file.

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

3 Comments

After exporting, was the Service imported in server.ts. Something like this: import {Service} from './app.ts'. ?
I am trying to import like this - import Service=Service; but i am getting the error - can not find service. But when i am doing like yours, i am no more getting the error. Can you tell me, why my syntax is not working. But syntax is working when i m removing the require statement.
import Service = require(./app.ts) is used when a single object is exported from the module using export = . That might be the reason. Have a look here. Under the section export = and import = require(), you will find your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.