0

I have a problem that I suppose comes from my ASP.NET MVC project using Type Script. For testing I have created a project using the HTML TypeScript template. I could perfectly create two modules and use one of them in the other like this:

import authModule = module("Authenticate");
import testModule = module("TestModule");

export module SiteMaster {
  authModule.Authenticate.run();
  testModule.TestModule.run();
}

It is generating correctly the JavaScript like this:

define(["require", "exports", "Authenticate", "TestModule"], function(require, exports, __authModule__, __testModule__) {
  var authModule = __authModule__;
  var testModule = __testModule__;

  (function (SiteMaster) {
    authModule.Authenticate.run();
    testModule.TestModule.run();
  })(exports.SiteMaster || (exports.SiteMaster = {}));
})

Then I have copied to my ASP.NET MVC 4.5 the compiler command from my Typescript project.

  <Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; --module amd @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

It is compiling correctly. Apparently is compiling correctly.

But there is a problem: when I create the same modules in my ASP.NET MVC application I receive the compilation errors in the import line:

The name '"Authenticate"' does not exist in the current scope
A module cannot be aliased to a non-module

Ths same for TestModule.

I have included a reference below to the module and the error remains, and look in the Typescript template the reference was not necessary.

/// <reference path='Authenticate.ts'/>

What is wrong here?

2 Answers 2

1

I think I have solved the problem. As I suspected it was in the compiler command. I fact I was not using the compiler command generated the TypeScript template.

I was using, in my ASP.NET MVC project this command:

  <Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; --module amd -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" IgnoreExitCode="true" />

This compiler command here is working:

  <Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; --module amd @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

Can someone explain me what is the meaning of the target parameter.

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

3 Comments

Typescript supports targetting ECMAScript 5 language features. If you don't specify ES5 as target it will assume the default ECMAScript Version 3.
But when I use the ECMAScript 5 I cannot compile the import. What should I do to compile the import command and use ECMAScript 5 ?
I'm pretty much convinced that this is not an ECMAScript 5 problem. However, to debug this I would need all code in order to compile it myself. Can you create a gist?
0

If you are using ASP.NET 4.5, I would personally recommend using bundles, rather than AMD module loading - unless you have a compelling reason not to.

Remove --module amd from the Exec config and convert your import statements into /// <reference path= statements and set up your bundle in bundle_config.

If you are targeting ES5, you use:

--target ES5

But you should only need to do this if you are using getters and setters, which is the only TypeScript language feature that cannot work on ECMAScript 3.

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.