5

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.

5
  • You need to reference the .js file that compiled from the .ts file.. browsers dont know how to deal with .ts files Commented Oct 23, 2012 at 13:49
  • Nothing was compiled as I stated in my question. Commented Oct 23, 2012 at 13:53
  • Also, if you see the Tutorial section on the TypeScript website, they also use <script src="greeter.Ts"></script> - directly referencing the .ts file. Either way, I can't get it to work or compile. Commented Oct 23, 2012 at 13:59
  • 1
    You are wrong.. check again.. copy/paste from the sample you sent: <script src="greeter.js"></script> Commented Oct 23, 2012 at 14:02
  • Ohhhh! Sorry, my mistake. Damn thing still don't compile though lol. Commented Oct 23, 2012 at 14:25

2 Answers 2

2

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.

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

2 Comments

I tried adding it to PATH, and that didn't work. I then tried using the full file path in the command window, and that didn't work either. I'm checking out the HTML APP with TypeScript now.
Thank you @WDever. I got it working (with the HTML App) and also by dragging and dropping my .ts files onto the tsc Compiler file itself lol.
2

A simple way to get tsc working on the command line is using nodejs and the corresponding package manager npm. You can get them from nodejs.org. Once you have set up nodejs, all you have to do is install the compiler with

npm install -g typescript

Executing Typescript directly in the browser is rather complicated. Typescript compiles to Javascript, so what you want is reference the compiled code in your html.

2 Comments

What compiled code are you referring to? Do you mean my compiled code? As in the code that I could not get to compile? That's what I'm trying to do.
My answer has two parts. The first part tells you how to get the compiler installed on the command line. The second part points out the you don't actually reference typescript in the browser. Your question mentions that you reference a typescript file in the browser, which you should not do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.