TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

TypeScript: a language for application-scale JavaScript development

474 点作者 D_Guidi超过 12 年前
TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source. From Microsoft.

66 条评论

cek超过 12 年前
Say what you want about whether this is a good idea or not, it is clear at least part of MS is really serious about open source.<p>* TypeScript is under the Apache 2.0 license [1]<p>* Source is available via git on Codeplex [2]<p>* Installation is as easy as <i>npm install -g typescript</i> [3]<p>Extra bonus coolness: They've provided an online playground like jsfiddle! [4].<p>[1]<a href="http://typescript.codeplex.com/license" rel="nofollow">http://typescript.codeplex.com/license</a><p>[2]<a href="http://typescript.codeplex.com/SourceControl/changeset/view/d397c54a55db" rel="nofollow">http://typescript.codeplex.com/SourceControl/changeset/view/...</a><p>[3]<a href="http://www.typescriptlang.org/#Download" rel="nofollow">http://www.typescriptlang.org/#Download</a><p>[4]<a href="http://www.typescriptlang.org/Playground/" rel="nofollow">http://www.typescriptlang.org/Playground/</a>
评论 #4597932 未加载
评论 #4598394 未加载
评论 #4598974 未加载
评论 #4599806 未加载
评论 #4597962 未加载
评论 #4598496 未加载
评论 #4599115 未加载
评论 #4598867 未加载
评论 #4598888 未加载
评论 #4598422 未加载
wingspan超过 12 年前
Awesome, great to see this finally released. I'm a dev in FUSE Labs (<a href="http://fuse.microsoft.com" rel="nofollow">http://fuse.microsoft.com</a>) and we've been dogfooding TypeScript for a while now. I'd be happy to answer any questions about using TypeScript vs vanilla JS, converting a large codebase, etc.
评论 #4598165 未加载
评论 #4598730 未加载
评论 #4598103 未加载
arturadib超过 12 年前
All of these compile-to-JS efforts are great, and as much as I love things like CoffeeScript I have to say I definitely worry about language fragmentation.<p>JavaScript is full of flaws, but its monopoly in the browser space has brought about one intriguing and welcome side-effect: a VERY efficient market for both employers and employees.<p>It's easy to overlook how important this common denominator has been for everyone involved. Employees have a tremendous amount of mobility within the industry: don't like your current JavaScript job? No problem - just about every dot-com needs a JavaScripter. Similarly, companies can today tap into a tremendous pool of JavaScript developers.<p>In today's fast-paced development environment, the ability to hit the ground running is key, and I worry that fragmentation will introduce unnecessary friction in the industry.
评论 #4598274 未加载
评论 #4599118 未加载
评论 #4598196 未加载
评论 #4598158 未加载
评论 #4598356 未加载
评论 #4598176 未加载
epidemian超过 12 年前
It looks <i>really</i> good for a first release. The focus on tooling is IMO the most refreshing thing about the project; the playground is great!<p>I haven't dug much into it yet, but there are a couple of annoyances that i noticed in the playground that i wish will be corrected/alleviated somehow:<p>- The language is not expression-oriented. Once i got used to the "everything is an expression" mindset in languages like CoffeeScript or Ruby (or every functional language that i can think of) it feels quite tedious to "go back" and remember that, no, now the "if" is not an expression any more, you can't return it, or pass it to a function, or assign it to something. You can use the special syntax of the "?:" operator for an if-expression, but there is no equivalent for "switch", or "try", or "for".<p>- The type system doesn't seem to support parametric polymorphism. For example, the type of string[]::map is ((string, number, string[]) =&#62; any, any) =&#62; any[] instead of ((string, number, string[]) =&#62; T, any) =&#62; T[]. So the value ["hello", "world"].map((s) =&#62; s + '!') is of type any[] instead of string[], which would be preferable IMO.
评论 #4598836 未加载
scanr超过 12 年前
Very interesting. The Apache 2.0 Licence is comforting, makes it worth having a look. The docs are here for anyone interested in the spec:<p><a href="http://typescript.codeplex.com/documentation" rel="nofollow">http://typescript.codeplex.com/documentation</a><p>I like what they've done. Nothing too revolutionary, mostly adding static typing to Javascript without straying to far from the existing (or future) language or increasing the noise significantly.<p>Here's some highlights:<p>* Type inference<p><pre><code> function f() { return "Hello World!"; } </code></pre> Will do the right thing<p>* Explicit Typing<p><pre><code> function f(s: string) { return s; } </code></pre> * 'Ambient Types'<p>To facilitate integration into existing JS libraries or the DOM, TypeScript lets you specify 'placeholders' for variables / classes that the runtime would expect to see e.g.<p><pre><code> declare var document; </code></pre> Almost a kind of dependency injection but also a neat way to manage talking to existing code.<p>* Structural Typing<p>* Classes and Interfaces<p><pre><code> interface BankAccount { balance: number; deposit(credit: number): number; } class CheckingAccount extends BankAccount { constructor(balance: number) { super(balance); } writeCheck(debit: number) { this.balance -= debit; } } </code></pre> * Modules<p><pre><code> module M { var s = "hello"; export function f() { return s; } } </code></pre> * Arrow function expressions<p><pre><code> (x) =&#62; { return Math.sin(x); }</code></pre>
评论 #4598675 未加载
评论 #4599635 未加载
oinksoft超过 12 年前
It seems to me that the type checking in TypeScript is extremely limited compared to what the Closure Compiler supports. The examples only show simple `fooInstance : Foo` examples, whereas Closure supports function prototype validation and such, a la C. I will need to see more elaborate examples.<p>Granted, there is no documentation that I could find on the website. I understand that this is a "preview," but I disagree with this way of presenting a tool. When the Closure Library was released, for instance, it was absolutely chock full of API documentation. This is because it was used for real-world projects and extensive docs mattered, even internal to Google.<p>There is a language specification (PDF, in the source tree) which is encouraging, but where's the manual? &#60;<a href="http://www.floopsy.com/post/32453280184/w-t-f-m-write-the-freaking-manual&#62;" rel="nofollow">http://www.floopsy.com/post/32453280184/w-t-f-m-write-the-fr...</a>. The specification is largely a rewording of the ES5 spec with insertions where the typing additions are important. It will take a good bit for the reader to separate the wheat from the chaff, as they say.<p>I have more than a sneaking suspicion that this project is essentially a proof-of-concept, and that it is not heavily used at Microsoft. Do you remember "Microsoft Atlas" in 2006, at the height of the JS DOM Library Wars? In the end, they just pushed their developers to use jQuery with some code generation helpers. Microsoft's open-source track record for JavaScript is not impressive, and I think you'd be a damned fool to invest in this technology for any serious project.
评论 #4598979 未加载
评论 #4598883 未加载
评论 #4620850 未加载
spicyj超过 12 年前
This looks nice. I love the fact that there's no runtime that needs to be included or any overhead when the compiled JS runs.<p>It'd be 100% more useful if it was more aware of nullable types -- as it is, it appears that<p><pre><code> null * 7 </code></pre> compiles without any error messages. If they add a "nullable number" type distinct from "number", I'll be a lot more likely to use it.<p>It also appears that some other things compile that perhaps shouldn't, such as<p><pre><code> 7[2] </code></pre> and<p><pre><code> 7["a"] </code></pre> even though (7).a is equivalent and (correctly) fails to compile.
评论 #4598292 未加载
swannodette超过 12 年前
They've added type annotations to all of jQuery it seems?<p><a href="http://typescript.codeplex.com/SourceControl/changeset/view/d397c54a55db#typings%2fjquery.d.ts" rel="nofollow">http://typescript.codeplex.com/SourceControl/changeset/view/...</a>
eddieplan9超过 12 年前
This is quite impressive technically, and I think the type-checking feature alone can make it appeal to those making large-scale application in collaborative development environment. I hope this inspires other similar efforts. A quick run-down of features:<p>- It's a superset of JavaScript. So there is no porting effort needed. (With CoffeeScript, you do not need to port if you don't want to.)<p>- compile-time type checking, like type erasure in Java's generics.<p>- module support at the language level. It's very thin. It does not give your AMD or CommonJS module, but you can easily hack around it.<p>- class and inheritance support at the language level. The implementation is very similar to CoffeeScript's.
评论 #4598815 未加载
tlack超过 12 年前
Weird that I didn't spot a friendly list of features.. seems to have some cool ones, like a shortened function expression (from the doc PDF):<p><pre><code> (x) =&#62; { return Math.sin(x); } </code></pre> and modules, which are implemented using the immediately invoked function expression pattern:<p><pre><code> module M { var s = "hello"; export function f() { return s; } } </code></pre> Syntax seems more clear than CoffeeScript and tool chain will probably shape up better. Looking forward to seeing this get some traction.
评论 #4598107 未加载
评论 #4598070 未加载
tlrobinson超过 12 年前
This looks great, but the IDE seems to be one of the key features, so we're going to need something other than Visual Studio.<p>EDIT: they've got syntax highlighting for some other editors, but full completion and error reporting is still needed <a href="http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx" rel="nofollow">http://blogs.msdn.com/b/interoperability/archive/2012/10/01/...</a>
评论 #4598130 未加载
评论 #4598204 未加载
评论 #4598491 未加载
ericcholis超过 12 年前
Favorite part about this, I didn't know it was Microsoft until I scrolled down!
评论 #4598440 未加载
MicroAndMacro超过 12 年前
Sublime Text, Vi, Emacs: TypeScript enabled <a href="http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx" rel="nofollow">http://blogs.msdn.com/b/interoperability/archive/2012/10/01/...</a>
alexanderh超过 12 年前
What about debugging? Thats my biggest problem with coffeescript<p>How do they map errors thrown in the browser, to TypeScript code? If this has things like classes and such, the relationship isnt always going to be 1:1 and debugging can become a nightmare. Part of what makes javascript so great is how easy it is to debug. All these "superset" languages that compile to javascript fail hard @ debug support usually
评论 #4598611 未加载
评论 #4598587 未加载
评论 #4598317 未加载
malandrew超过 12 年前
Like someone else commented in the TC article about Typescript, this Resig quote, changing "Google" for "Microsoft" is relevant:<p><pre><code> "Why is [Microsoft] putting time and effort into changing JavaScript when the DOM is what needs fixing?" </code></pre> <a href="https://twitter.com/jeresig/status/124114331616026624" rel="nofollow">https://twitter.com/jeresig/status/124114331616026624</a>
评论 #4599700 未加载
lukeholder超过 12 年前
Can I write my TypeScript in coffeescript?
评论 #4597888 未加载
streptomycin超过 12 年前
This seems similar to the type checking and optimization done by Google Closure Compiler?
评论 #4598368 未加载
koops超过 12 年前
I've written a lot of JavaScript, including large-scale projects, and never once have thought, "Gee, I wish I had type checking."<p>Haven't we come to a consensus that types are more trouble than they're worth? They hurt clarity and catch few bugs.
评论 #4598019 未加载
评论 #4598037 未加载
评论 #4598025 未加载
评论 #4598215 未加载
评论 #4598358 未加载
andrewla超过 12 年前
On a tangent, does anyone know anything about the in-browser editor they are using for the playground? It seems really slick. The javascript references something called "monaco" and the directories are all prefixed with "vs".<p>The code is hosted on their demo site; /Script/vs/editor/editor.main.js appears to be the main js file and has this notice:<p><pre><code> /*! © Microsoft. All rights reserved. This library is supported for use in Windows Store apps only. Build: 1.0.8514.0.win8_rtm.120711-1900 Version: Microsoft.WinJS.1.0 */</code></pre>
评论 #4598345 未加载
drcode超过 12 年前
Back in the day, Microsoft would use a strategy called "embrace, extend, extinguish." <a href="http://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish" rel="nofollow">http://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish</a><p>Recently, Microsoft has been pushing Javascript very hard (embrace) and now it looks like they've started the "extend" phase.<p>Luckily, no one really worries about them being able to pull off the "extinguish" part anymore... they just don't have enough market power these days.<p>EDIT: Yes, I conceede the fact that TypeScript is OS probably addresses most of these objections.
评论 #4598075 未加载
评论 #4598045 未加载
评论 #4598097 未加载
评论 #4598043 未加载
kombine超过 12 年前
Now I want to take an advantage of strict typing at runtime, which is obviously not possible, because instead of standardizing a VM all vendors are doing stupid things like this.
评论 #4597910 未加载
luke_s超过 12 年前
It seems the analyser to infer the types of your vars is fairly easily fooled. The following code compiles, but prints out "Hello undefined":<p><pre><code> interface person{ firstname; lastname; } interface apple{ colour; } function hello(p : person){ alert("hello " + p.firstname); } var aPerson = {firstname: "joe", lastname : "blogs"}; var anApple = {color: "red"}; var foo; if(true){ foo = anApple; } hello(foo);</code></pre>
评论 #4601924 未加载
DigitalSea超过 12 年前
I will admit MS have impressed me here. The fact they've released TypeScript under an Apache 2.0 licence and put the code up on CodePlex goes to show Microsoft are making strides in the open source community. A big change considering the mentality of MS used to be open source was unsafe and a threat to their dominance in the software industry. The world must be ending: Apple is starting to falter and Microsoft is climbing back to the top.
colin_jack超过 12 年前
In case anyones interested, dart JS interop:<p><a href="https://github.com/dart-lang/js-interop/" rel="nofollow">https://github.com/dart-lang/js-interop/</a>
emillon超过 12 年前
Very good idea. But note that these annotations are just hints : they are enforced only in simple cases :<p>var x = "lol" - error found : <a href="http://pastebin.com/R1wqp0CS" rel="nofollow">http://pastebin.com/R1wqp0CS</a> var x; x = "lol" - accepted : <a href="http://pastebin.com/0vc68RbY" rel="nofollow">http://pastebin.com/0vc68RbY</a>
mykolasmith超过 12 年前
Codeplex/samples/simple (<a href="http://bit.ly/Svcc4Y" rel="nofollow">http://bit.ly/Svcc4Y</a>) is the same as the CoffeeScript constructors doc section (<a href="http://bitly.com/PnLtGy" rel="nofollow">http://bitly.com/PnLtGy</a>)... Wonder what other stuff they borrowed from CoffeeScript?
评论 #4598079 未加载
anuraj超过 12 年前
Wholeheartedly support this thinking softie has no daggers hidden. The changes do make the language more readable and maintaninable compared to the mess called JavaScript. If the IDE is support is also there, this will be a no-brainer.
Floopsy超过 12 年前
(Wikipedia) “Some examples, like Dart, portend that JavaScript has fundamental flaws and to support these scenarios requires a ‘clean break’ from JavaScript in both syntax and runtime. We disagree with this point of view.” - Microsoft’s JavaScript team<p>If Google comes out with Dart, well, then there's no need for that. But it's ok for Microsoft to be secretly working on their own Javascript 2.0. Just sayin' - Why criticize Dart when you've just come with almost the same thing? :)<p>But snark aside, good job Microsoft. Well done.
评论 #4604297 未加载
评论 #4600286 未加载
libria超过 12 年前
It's good to see sharp developers like Anders Hejlsberg spearheading this. I really hope this means we'll get LINQ sometime in the future; good to hear generics are on the way.
iambot超过 12 年前
I worked on a joke/conversion project a little while ago that achieves the same ends without having to compile to JavaScript.<p>The only reason I wrote it was to prove to a co-worker who was "hating" on JavaScript that it IS possible to have a type system in JavaScript - if that's what you want. Its not the same end result but similar enough to warrant a mention.<p>Here's the repo: <a href="https://github.com/christopherdebeer/TypedFunc" rel="nofollow">https://github.com/christopherdebeer/TypedFunc</a>
dogada超过 12 年前
One of the key TypeScript features is not only the fact that JavaScript program is TypeScript programs but also ability to add type annotations to existing javascript libraries without changing of their source code. For example, see port of Backbone's TodoMVC: <a href="http://typescript.codeplex.com/SourceControl/changeset/view/d397c54a55db#samples%2ftodomvc%2fjs%2ftodos.ts" rel="nofollow">http://typescript.codeplex.com/SourceControl/changeset/view/...</a>
jonny_eh超过 12 年前
I was reading the synopsis on the page then it faded out and replaced it with sample code. Geez, let me read and then scroll down. WTF is with the carousel non-sense?
aaronblohowiak超过 12 年前
They added static typing to javascript, except you can still pass a number to a function that takes a string. In their example <a href="http://www.typescriptlang.org/Playground/" rel="nofollow">http://www.typescriptlang.org/Playground/</a> replace the<p><pre><code> new Greeter("World"); </code></pre> with<p><pre><code> new Greeter(5); </code></pre> and it still works. What good is adding types to functions if they are ignored?
评论 #4598652 未加载
评论 #4598622 未加载
zachrose超过 12 年前
Would it not be just as reasonable to put type information in JSDoc, and build a preprocessor that does the complaining?
charlieok超过 12 年前
So they've set up a site for TypeScript but as far as I can tell, that site hasn't got a blog. With so many projects vying for attention, subscribing to a project's blog is my default way of keeping it in mind for later. If they post interesting updates, I'll be reminded later to come back and give it a closer look.
dogada超过 12 年前
IMO Microsoft looks for web-developer loyalty because recent stupid policy of big monopoly drive them to zero share on web-browser market. The only remaining question: will IE10 support TypeScript or it will be added in IE11 only?
nnq超过 12 年前
The only thing that I find "exciting" in the land of compiled-to-javascript languages is LiveScript (<a href="http://gkz.github.com/LiveScript/" rel="nofollow">http://gkz.github.com/LiveScript/</a>)...
antidoh超过 12 年前
I wish they had named it something else. typescript is the default output file name for script(1).<p><a href="http://www.unix.com/man-page/Linux/1/script/" rel="nofollow">http://www.unix.com/man-page/Linux/1/script/</a>
SeanLuke超过 12 年前
&#62; The scope of a parameter, local variable, or local function declared within a function declaration (including a constructor, member function, or member accessor declaration) or function expression is the body of that function declaration or function expression.<p>This thing claims to be meant for "application-scale" JavaScript, and yet doesn't repair even JavaScript's most notorious error?<p>A suggestion to the authors. Purchase this book:<p><a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742" rel="nofollow">http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockfor...</a><p>... then go through the book with a fine-tooth comb, and every time it describes something as a "bad part" or an "awful part", delete or fix that misfeature in TypeScript.
评论 #4598656 未加载
stalled超过 12 年前
(for posterity, stray duplicate discussion with exactly the same url: <a href="http://news.ycombinator.com/item?id=4597724" rel="nofollow">http://news.ycombinator.com/item?id=4597724</a>)
euroclydon超过 12 年前
What unit test framework are they using in the source? It looks like Jasmine ('describe', 'it') but then it has 'assert' and I can't find an include for it.
jon6超过 12 年前
<p><pre><code> $ t command not found </code></pre> clearly they could have named the compiler just 't' instead of the overly verbose 'tsc'. all those extra characters!!
评论 #4598521 未加载
评论 #4598380 未加载
评论 #4598448 未加载
wicknicks超过 12 年前
Looks really good. The IDE support looks like a big bonus. Wish this had been released on a Friday -- have to wait a bit before I can dig deeper!
bilalq超过 12 年前
Am I the only one experiencing sluggish scrolling on that site? Rather ironic for a site boasting about application-scale development.
ww520超过 12 年前
This looks very good enhancement on top of Javascript. Hope browsers start bundling the TypeScript compiler natively.
bbayer超过 12 年前
yet another language compiled to javascript. What is the deal with the adding type system without doing runtime checks? Does it solve DOM manipulation complexity or it just solve code readability problem? Does it worth to learn new language constructs when you decide to begin low or middle scale projects?
dotborg超过 12 年前
Reminds me about Turbo Pascal, I love it!
stuaxo超过 12 年前
Hm.. classes, interfaces... reminds me of AS3; which of course MS stopped becoming the next javascript.<p>Still - looks useful.
Zelphyr超过 12 年前
The Google guys called. They want Microsoft to stop being jealous of the JS-influenced turd that is Dart.
ilaksh超过 12 年前
Not having to deal with types is one of the advantages of JavaScript. This actually makes it worse.
buremba超过 12 年前
I think javascript is awesome enough so it doesn't need any language improvements. The only improvement over javascript is coffeescript and it's just because its syntax nothing more else. take a look at this video from google i/o: <a href="http://goo.gl/BGvAS" rel="nofollow">http://goo.gl/BGvAS</a>
FreshCode超过 12 年前
Could TypeScript be combined with the CoffeeScript syntax to save keystrokes?
clockwork_189超过 12 年前
Seems pretty cool, but how does it compare to DART or does it even compare?
iamleppert超过 12 年前
Why does everyone want to take all the nice features of javascript, it being so loose and freeform and turn it into Java? I don't need interfaces and classes built into the language. That's why it's so powerful and lightweight. Prototypical!<p>People keep making the same mistakes, if you let them.<p>No thanks.
评论 #4598574 未加载
评论 #4598783 未加载
评论 #4598649 未加载
devongovett超过 12 年前
My thoughts on Badass JS here: <a href="http://badassjs.com/post/32674515997/typescript-microsofts-new-typed-javascript-dialect" rel="nofollow">http://badassjs.com/post/32674515997/typescript-microsofts-n...</a>
petegrif超过 12 年前
MS answer to DART?
euroclydon超过 12 年前
The compiler's written in... TypeScript!
Andi超过 12 年前
For stuff like this, you use schema.js.
wensheng超过 12 年前
No list comprehension? No, Thanks.
评论 #4598181 未加载
dreamdu5t超过 12 年前
The lack of strong typing in JavaScript is a <i>feature</i> not a bug.
mbq超过 12 年前
Looks like all the bad features of Java and JS combined.
zoowar超过 12 年前
lol: application-scale
dmorgan超过 12 年前
Open Source? Node.js? Github? Javascript cross-compiler? ES6 based? Type annotations?<p>This is the first sign that they are "getting" 2012 developers and are back in the game with a vengeance. Hope it works.<p>Dart is mid-nineties MS by comparison.
camus超过 12 年前
Funny how Microsoft refused ES4 because it came from Macromedia/Adobe ,yet now it pushes a language that looks like its own JScript/AS3
pootch超过 12 年前
MS has no credibility in this space. If you think slapping an OSS license on their code gives them cred you must be some kind of fanboy. As for Javascript - well, browsers still sucks, webapps still suck, and web development still sucks. Javascript is a big part of that. 30%
init0超过 12 年前
<a href="http://i.imgur.com/XB3ib.png" rel="nofollow">http://i.imgur.com/XB3ib.png</a> Oh M$ Oh...
评论 #4598053 未加载
评论 #4598048 未加载