0

Currently my code looks like this:

module Nexus {

    export class Scraper {

        private summonerName: string;

        private apiKey: string = '';

        private summonerStatsUrl = '';

        constructor(name: string) {

            this.summonerName = name;
        }

        getSeasonRank(): string {

            return 'aa';
        }

        getRankedStats(): string {

            return 'aa';
        }

        getSummonerStats(callback: Function) {

            var summonerStats = request(this.summonerStatsUrl + this.apiKey, function (error, body, response) {

                callback(response);
            });
        }
    }
}

And app.ts:

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

var colors = require('colors'),
    request = require('request'),
    fs = require('fs'),
    readline = require('readline'),
    rl = readline.createInterface({

        input: process.stdin,
        output: process.stdout
    });

rl.question('Insert summoner name: \r\n >> ', function (answer) {

    var scraper = new Nexus.Scraper(answer);

    scraper.getSummonerStats(function (result) {

        console.log(result);
    });
});

When I reach the new Nexus.Scraper(), I'm getting this error:

Nexus is not defined

While it should be since I'm including it? The module is named Nexus and I'm exporting the Scraper class. (The file is called Nexus.ts.)

1
  • It is recomended that a module name should start with a lowercase letter. And what is "///<reference path="./Nexus.ts"/>" ? Is Nexus a class ? The name of the typescript file should be same as name of class. And your app.ts should be inside the same module i.e. nexus. Then it will work Commented Mar 27, 2015 at 12:12

2 Answers 2

2

Make sure your module looks as follows:

module Nexus {
    export class Scraper {
        private summonerName: string;
        private apiKey: string = '';
        private summonerStatsUrl = '';

        constructor(name: string) {

            this.summonerName = name;
        }
        
        getSeasonRank(): string {

            return 'aa';
        }
        
        getRankedStats(): string {
            return 'aa';
        }
        
        getSummonerStats(callback: Function) {
            var summonerStats = request(this.summonerStatsUrl + this.apiKey, function (error, body, response) {
                callback(response);
            });
        }
    }
}

export = Nexus;

Then, rather than using /// <reference /> do this:

import Nexus = require('Nexus');
Sign up to request clarification or add additional context in comments.

Comments

1

You also need to export the module

export module Nexus {
    ...
}

then in your app.ts you can call it like:

import Nexus = require('./Nexus.ts');

2 Comments

'Cannot find name Nexus' on app.ts
You will also need to require it on app.ts, if I am not mistaken.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.