Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running TypeScript project in the browser

I found out about TypeScript, and installed the Visual Studio 2012 Plugin, downloaded the source code and ran the first sample after referencing the .ts file in my HTML document:

function Greeter(person) {
    return "Hello, " + person + ".";
}

var user = "James Kent";

document.body.innerHTML = Greeter(user);

And then proceeded to compile the code at the command-line, with:

tsc greeter.ts

But I could not compile it, as Visual Studio says:

Command "tsc" is not valid.

After looking all over the TypeScript website, I was unable to find any information about how to get it working. A Google search also yielded no relevant results.

How can I get TypeScript working?

Update: Running any of the samples provided with the source code simply displays a blank page in any browser. However, samples appear to work just fine on the TypeScript website.

like image 356
Arrow Avatar asked Oct 07 '22 05:10

Arrow


1 Answers

Your system cannot find the path to the compiler. The compiler executable is here (on my x64 Win 8 system) if you want to register it yourself.

C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.8.0.0\

Use it to compile the .ts file to a .js, and use that in your html instead of trying to compile it directly in the browser. That would be really slow.

You can look at the "HTML Application with TypeScript" project in VS, it is configured to compile your TypeScript at the project build.

like image 177
Roy Avatar answered Oct 09 '22 01:10

Roy