1

In TypeScript, I have a code like this:

levenstein/LevensteinAlgorithm.ts

export module levenstein {
    export class LevensteinAlgorithm
    {
        getDistance(left: string, right: string): number {
        // Some code for the alogorithm...
        }
    }
}

To have a unit test for it, I have written a test in another path:

tests/levensteinAlgorithmTests.ts

/// <reference path="../scripts/typings/qunit/qunit.d.ts" />
/// <reference path="../levenstein/levensteinalgorithm.ts" />

QUnit.module("levensteinalgorithm.ts tests");

import levenstein = require("levenstein/LevensteinAlgorithm");

test("Simple update cost is equal to 1", ()=> {
// Arrange
var leven = new levenstein.LevensteinAlgorithm();

//... 

Unfortunately it has a build error saying:

Property LevensteinAlgorithm doesn't exist on type: ....

I'm using QUnit and Chutzpah to run the tests.

What's the problem with my module loading?

1 Answer 1

2

Because you wrapped LevensteinAlgorithm in the internal module levenstein in an external module, the way to reference that object once you've imported it as levenstein is levenstein.levenstein.LevensteinAlgorithm.

The best fix here is to just remove the export module Levenstein { from LevensteinAlgorithm.ts and export the class directly out of the external module.

See also the "Needless Namepsacing" heading here: https://typescript.codeplex.com/wikipage?title=Modules%20in%20TypeScript

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

Comments

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.