最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running TypeScript project in the browser - Stack Overflow

programmeradmin2浏览0评论

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 pile the code at the mand-line, with:

tsc greeter.ts

But I could not pile 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.

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 pile the code at the mand-line, with:

tsc greeter.ts

But I could not pile 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.

Share Improve this question edited Oct 25, 2018 at 3:16 cancerbero 7,0451 gold badge36 silver badges26 bronze badges asked Oct 23, 2012 at 13:27 ArrowArrow 2,9248 gold badges41 silver badges61 bronze badges 5
  • You need to reference the .js file that piled from the .ts file.. browsers dont know how to deal with .ts files – udidu Commented Oct 23, 2012 at 13:49
  • Nothing was piled as I stated in my question. – Arrow 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 pile. – Arrow 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> – udidu Commented Oct 23, 2012 at 14:02
  • Ohhhh! Sorry, my mistake. Damn thing still don't pile though lol. – Arrow Commented Oct 23, 2012 at 14:25
Add a ment  | 

2 Answers 2

Reset to default 2

Your system cannot find the path to the piler. The piler 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 pile the .ts file to a .js, and use that in your html instead of trying to pile 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 pile your TypeScript at the project build.

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

npm install -g typescript

Executing Typescript directly in the browser is rather plicated. Typescript piles to Javascript, so what you want is reference the piled code in your html.

发布评论

评论列表(0)

  1. 暂无评论