Why does TypeScript have to be the answer to anything?

9 篇文章 0 订阅
4 篇文章 0 订阅

DISCLAIMER: I don't work on TypeScript. I am not involved with that team and this is all my own opinion and conjecture.

TypeScript was announced and folks are saying "TypeScript is clearly Microsoft's answer to Google's Dart" or "So TypeScript is Microsoft's answer to CoffeeScript."

I was chatting with Jez Humble today about the intense interest and some little gnashing of teeth around TypeScript and he offered this little gem of a quote:

It's disappointing when smart people display a profound ignorance of computing history. - Jez Humble

TypeScript has been out a day. It's way early to see if it has legs, but it seems initially promising.

TypeScript and Dart

People have compared TypeScript to Dart. That's comparing apples to carburetors. TypeScript builds on JavaScript so there's no JS interop issues. Dart is a native virtual machine written from scratch. Dart interops with JavaScript...but it's not JS. It doesn't even use the JavaScript number type for example.

TypeScript and CoffeeScript

I'm a huge CoffeeScript fan although it is a different language with a syntax of its own to learn. What I like about TypeScript - so far - is that TypeScript’s static typing could enable better tooling with warning squiggles, easy statement completion, plus smart refactoring. You also get easy navigation around code, as well as find references, rename, and more. You don’t currently get that in CoffeeScript.

So what is TypeScript?

TypeScript is a superset of JavaScript and you write it like you write JavaScript which I like. Any existing JavaScript is already TypeScript. One argument has been made that TypeScript is for people who don't want to learn JavaScript. I don't buy that. As Ward Bell said in an email:

TypeScript is not a crutch any more than JSLint is a crutch. It doesn’t hide JavaScript (as CoffeeScript tends to do). - Ward Bell

I think Ward says it well. Folks rail against static typing but they don't complain about JSLint. TypeScript offers optional type annotations - it's hardly a perversion of JavaScript.

From what I can see after using TypeScript for a few days is this. It gives you type checking, explicit interfaces and easier module exports. In fact, it's a little like getting some of tomorrow's ECMAScript 6 early in a way that's compatible with today's JavaScript. ES6 won't be out for at least a year but we can play with some of those features today.

Things that I like about TypeScript:

  • It's Open Source and under the Apache 2.0 license
  • You can install the tools easily with
    • npm install typescript -g
  • You can git the source
    • git clone https://git01.codeplex.com/typescript 
  • You can play with it online at http://www.typescriptlang.org/Playground

Things I don't like about TypeScript (these are mostly implementation things)

  • No splitscreen editor like Visual Studio's existing CoffeeScript editor
    • UPDATEWhile this isn't "official" support, Mads has updated Web Essentials 2012 with a splitscreen editor. The two teams are going to work together on a more official solution.
  • Doesn't generate .js on save, requires a build.
  • You have to add a BeforeBuild target to your ASP.NET application's CSPROJ:
<Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

I will continue to use TypeScript and evaluate it, but I think the fact that it's open source, it creates JavaScript and it feels comfortable to me as a C# programmer means it will fill a useful niche.

This quote from Luke Hoban, co-creator of TypeScript really hits the spot.

"CoffeeScript is to Ruby as TypeScript is to Java/C#/C++." - Luke Hoban

If you love Ruby, you'll enjoy CoffeeScript as it makes the JavaScript more like the Ruby. The same is true with TypeScript. It brings useful features into JavaScript in an ultimately compatible and syntax-friendly way using language constructs you're comfortable with.

原文地址:http://www.hanselman.com/blog/WhyDoesTypeScriptHaveToBeTheAnswerToAnything.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值