1

This is a legacy project so I'm not going to change everything to TypeScript, but I do want to slowly start combining it, so I want to call TypeScript code from normal JS, using RequireJS. I have a 1-login.js and realtimeConnection.ts (that's transformed into realtimeConnection.js):

<script type="text/javascript" data-main="/content/scripts/realtimeConnection.js" src="/content/require.min.js"></script>
...
<script type="text/javascript" src="/content/pages/1-login.js"></script>

This is 1-login.js:

(function ($) {
    requirejs(["/content/scripts/realtimeConnection.js"], function (rtCon) {
        debugger;
        // The probelm: rtCon === undefined
    });
    ...
    ...
}(jQuery));

realtimeConnection.ts:

export class RealtimeConnection {    
}

Which in turn becomes realtimeConnection.js:

"use strict";
var RealtimeConnection = (function () {
    function RealtimeConnection() {
    }
    return RealtimeConnection;
}());
exports.RealtimeConnection = RealtimeConnection;

So how do I expose my TS code to the JS code via RequireJS?

1 Answer 1

3

Ok found it: I needed to tell the TypeScript compiler to build it in a RequireJS/AMD style:

Since I'm using Visual Studio 2015, I placed a tsconfig.json file with the appropriate settings ("module": "amd" in particular) in the root content dir, as per this SO answer.

Now it works.

Now to whoever going to mark it as duplicate:

That allegedly duplicate question, which its answer I linked above, has the title "Visual Studio 2015 RC does not create sourcemap when saving Typescript file". The answer is the same, but the question is different.

I found my answer, hope it'll help others as well... BTNOMB.. just saying...

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.