8 ms·
Why Angular 2 Switched to TypeScript
- iLoch 10y agoI wanted to use TypeScript with a new React project, but the biggest problem I had (which eventually lead me away from using it) was that typings were so hard to get ahold of. Built something in JS? Sorry, you have to provide what is essentially a source map in order to get it to work with TypeScript. That should be a non-starter for anyone who is doing more than a hello world app. Figure out a way for me to use TS without having to create a bunch of extra type garbage in my app and I'll upgrade my code base immediately.
- cheez 10y agoI was under the impression that typescript is a superset of javascript. Is that not the case?
- rplst8 10y agoIt is. I've not written anything in it other than a few simple tutorials, so I'm not an expert, but from what I've read you can drop to straight JS in your TS source code.
- dweinus 10y agoThe title of one of the article sections is literally "TypeScript is a Superset of JavaScript" ...people do still read before commenting, right?
- cheez 10y agoJust wondering why you can't use React directly if that is the case
- iLoch 10y agoIn order for TypeScript to understand the types it is interfacing with (especially in the case of libraries) there has to be a type definition created for each library. Dismissing my complaint because "TypeScript is a superset of JavaScript" shows a lack of understanding regarding how the system works.
- abritinthebay 10y agoIt is, but that means less than most TS advocates realize. I mean Objective-C is something like 97% a superset of C... doesn't make the transition any easier.
- smt88 10y agoThere is a huge difference between 97% superset and 100% superset. JS is valid TS without changing anything. The transition is easy.
- abritinthebay 10y agoActually there is only a 3% difference. Which isn't actually that huge (most not hugely complex C programs are valid Objective-C programs, at least with a couple of minor tweaks). As I said - it's a silly marketing point that isn't convincing anyone already not convinced by TypeScript and they'd do better to drop it as a talking point.
- kfinley 10y agoTypeScript 2 adds Easier Module Declarations[0]. So if a library doesn't have a type definition, you can silence errors by adding: declare module "some-module" Does that help? 0: https://blogs.msdn.microsoft.com/typescript/2016/07/11/announcing-typescript-2-0-beta/ https://blogs.msdn.microsoft.com/typescript/2016/07/11/annou...
- iLoch 10y agoYes that does actually. My experience may have been with an earlier version of TypeScript. I haven't looked at it in a few months.
- k_bx 10y agoTypeScript 2 milestone on github shows it's pretty far from a release (imho). I liked Facebook's Flow language more, but it seems to be less popular.
- ctolkien 10y agoV2 is currently in beta. > In the coming weeks, a more stable release candidate will be coming out, with the final product landing not too far after. -- https://blogs.msdn.microsoft.com/typescript/2016/07/11/announcing-typescript-2-0-beta/ https://blogs.msdn.microsoft.com/typescript/2016/07/11/annou...
- k_bx 10y agoGithub says "40% complete" in a milestone, that's where I got the impression from https://i.imgur.com/DQoyGeW.png https://i.imgur.com/DQoyGeW.png .
- k__ 10y agoreally? I have the complete opposite feeling, when looking into the TS2 repo.
- 10y ago
- Doolwind 10y agoMost popular projects have typescript bindings. Check out https://github.com/DefinitelyTyped/DefinitelyTyped https://github.com/DefinitelyTyped/DefinitelyTyped for a big list. If you're using a library and can't find bindings then I've found it's worth the time creating them yourself for any reasonably sized project. This is annoying and time consuming up front, but the benefits you get down-stream easily repay this initial investment.
- ng12 10y agoTo me, this was the silliest thing about working on a large typescript project. It slowed build times, we had issues with GitHub throttling, and the typings were commonly incorrect or incomplete.
- mamp 10y agoSame happened with me. I then moved to flow-type (hint, install it via 'sudo npm install -g flow-bin'), and linter-flow for atom. It's a bit temperamental but the type inference means you don't have to be quite as explicit throughout all of your code. Already saved me a lot of frustration and time. Although TypeScript 2 is catching up, the fact that flow works with babel to support many ES6/ES7 features e.g. object spread. Coming most recently from F# I would have gone insane without some kind of static typing extension in Javascript.
- iLoch 10y agoWe use C#, and are hoping to move to .NET Core with future projects. I use Visual Studio Code exclusively, so TypeScript seemed like the obvious choice (I'm primarily a JS developer so I'm well aware of flow, however the support for TS in VS Code as a general solution to types in JS is unparalleled in my opinion). Not to mention Atom was ungodly slow on my high end MBP so I laughed and deleted it.
- jiaweihli 10y agoYou aren't required to use import, use require if you don't care for typings: `var aLibrary: any = require('aLibrary');`
- stevehiehn 10y agoSo far I'm really into typescript (for dev). However i one big problem which is C.I. It's annoying to have to configure an environment just to run a TS compile job.
- lomnakkus 10y agoI don't understand what you mean by "have to configure an environment just to run a TS compile job". Didn't you already have some sort of automated CI testing running on all your JS code?
- stevehiehn 10y agoReally I just didn't want to have to install node in the build step because it was already complex.
- lstamour 10y agoWhether it's TS or some other form of minification or listing, I find node on a build server is unavoidable these days. I just wish it used fewer resources during npm installs...
- lomnakkus 10y agoIt continues to be amazing to me that a new generation of developers is discovering that, yes, static checking adds a lot of value (for non-trivial-sized projects). Of course, if you were tasked with delivering web apps -- until recently -- you didn't really have any choice. The older I get, the more the whole "everything moves in cycles" thing appears to be true -- almost regardless of what particular subject matter is under consideration.
- stephen 10y agoAgreed; if you're looking for a tldr (edit: for sharing with others, e.g. I know you're convinced), I recently made a few edits to my pontification from awhile ago: http://www.draconianoverlord.com/2010/11/24/why-im-a-static-typing-bigot.html http://www.draconianoverlord.com/2010/11/24/why-im-a-static-... I really like the OP's point about "types make abstractions explicit". That is a great articulation that I'm going to add to my post as well, with attribution.
- reboog711 10y agoCycles... It doesn't seem too long ago when Java Developers rushed to Ruby because it wasn't statically typed. Now, TypeScript is better than JavaScript because of the opposite reason... I've seen this sort of pendulum swing a few times in my career.
- 67726e 10y agoI don't think it's fair to say "Java Developers" rushed to Ruby. Cargo-Culting, fad-chasing developers do. The fact is statically typed code eliminates whole classes of errors. There are some trade-off but I can't begin to consider the trade-off for anything non-trivial I want to survive for more than a year.
- kmiroslav 10y agoPretty sure that pendulum is never swinging back in the dynamically type side. The simple truth is that today, statically typed languages have all the advantages that once used to be the exclusivity of dynamically typed languages, while the reverse is still not true. In 2016, there is really very little reason to pick a dynamically typed language for any serious project. Javascript is going to be around for a while because of inertia, but it's pretty much the last mainstream dynamically typed language we'll see.
- stephen 10y agoQuestion for TypeScript and specifically Angular 2: does Angular 2 being written in TypeScript mean that webapps based on Angular 2 that are also written in TypeScript, are basically 100% type-safe (e.g. all app-to-Angular library calls, or within-app view-to-model/etc. calls, are all type checked)? I ask because after looking (admittedly very briefly) at writing an Ember app in TypeScript, it looked like because Ember assumes all of it's webapps will be JavaScript, there ends up being a lot of dynamic-/string-based idioms, e.g. model.set("property"). (There is a good SO post about turning this into a typed model.property.set(...) in TypeScript, but that solves just this one instance, and not the entire Ember experience.) So, this left me with the feeling that for a TypeScript webapp to have a truly great/first-class/typed interaction with it's framework (Angular, Ember, whatever), that the framework itself would have to: a) be written in TypeScript, and b) have the founding assumption that most (all?) apps written for it would also be TypeScript. So, per this post, Angular 2 is a), it's written in TypeScript. What about b)?
- lstamour 10y agob) is left as an exercise for the reader, to pick dependencies and protocols based on their merits, one consideration being support for types. But TypeScript does appear to be more than types alone, so there are other benefits. See also: AngularDart, which also has the same "b)" problem, but worse as it doesn't interact as easily with existing JS.
- ta_donk_gt 10y agoUsing TypeScript in Angular 2 is completely seamless, and I think most consider it the default, so 'b)' is likely close to what you describe. I don't think you could come close to approximating Angular 2's level of TypeScript integration with Ember. The one caveat is that templates have no type checking or refactoring support. This is fairly standard in html templates in any statically typed language framework, but it is still frustrating and unfortunate. You can safely rename a symbol in TypeScript files, and yet not be able to catch the references in templates without find and replace.
- continuational 10y ago
- Doolwind 10y agoIf you're looking for Typescript type definitions for a project you're using check this list - https://github.com/DefinitelyTyped/DefinitelyTyped https://github.com/DefinitelyTyped/DefinitelyTyped
- lstamour 10y agoGood list, but are they going alphabetically and only made it to 'k'? ;-) Edit: Thanks, I had a feeling there was a bug... it was just strange to see files from the top-level folder appear afterward, made it less obvious.
- Doolwind 10y agoThe list is truncated in web view on Github. If you use Visual Studio they all have nuget packages which lets you search for (and add them) easily to a project.
- dangoor 10y agoThe directory is too big for GitHub's web view, unfortunately. The type definitions are moving to npm, so hopefully they'll be easier to search/view.
- houli 10y agoNot sure if you're being serious but GitHub truncates to 1000 files/directories.
- jjude 10y agoYou can install typings (npm install -g typings) and then search for type definitions. For hapijs, it would be `typings search hapi`. Then you can install using `typings install dt~hapi --global --save`.
- shadowmint 10y agoThere are a lot of options available to frontend devs today: ES5, ES6 (Babel), TypeScript, Dart, PureScript, Elm, etc.. So why TypeScript?' ... Elm and PureScript are elegant languages with powerful type systems that can prove a lot more about your program than TypeScript can... ouch. Thats got to be a tiny bit awkward for the Dart team to read (so, I guess Dart isnt in the list of elegant languages then?)
- leshow 10y agoDart isn't even in the same progamming paradigm as Elm and Purescript, so I don't think it was meant as a slight towards the Dart team. And really, Dart is more like Java, it's nowhere near the elegance of the ML/Haskell pedigree of Elm and Purescript
- pjmlp 10y agoI think it should already be a pain point that internal Google teams decide to use languages designed by the competition instead of their own.
- pixie_ 10y agoI've been programming for a long time and TypeScript has been a slam dunk for me. It makes programming large web apps actually considerably more manageable. Unfortunately I spend a lot of time defending the merits of static typing to my co-workers. At the same time they're going on about how unit tests are important, while static typing eliminates entire classes of errors and they don't get it for some reason. Unit tests while important don't prevent type errors, and if you tried using them for that you'd have orders of magnitude more tests to write. I feel like I'm taking crazy pills having to defend static typing while every dynamic language I've used for any project of any considerable size has been a complete nightmare to manage. At this point I feel like a lot of new coders coming out of school just haven't written anything large enough yet and maybe that's why they don't see the point.
- bsaul 10y agoDon't worry, it's all coming to an end. All the trending languages either are statically typed ( go, swift, rust), or provide some kind of type hinting (elixir) to make up for it. Unit testing is great, but it doesn't provide autocompletion, or help you analyze your codebase before a refactoring.
- devuo 10y agoI feel your pain, intensely.
- nojvek 10y agoTypescript big value for me is code completion and refactoring. Their language server is like running the compiler on every keystroke. The squigglys are almost the same as what the compiler would say. When third party libs have dts files, it's a joy to use them.
- Yhippa 10y agoThe longer I work on bigger and complicated projects the more I'm thankful for static typing. I feel that static typing speeds up my development greatly and when I do have problems they're very easy to isolate and reason about. The tooling that enables is a huge speed boost as well.