Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'd love a pro con from someone who's really tried out both TypeScript and ES6 Javascript. What exactly is the use case that TypeScript allows one to write JS for that one can't just write JS for?


I've been using both for a few years (TS at my old job, es6 at my new job but we're moving to TS so now I'm using both depending on what I'm working on).

The use case I like most about typescript is it makes refactoring and making changes really painless. For example, in an angular app, you may have a service that several components rely on. When changing a method signature in the service, you'll get compile-time info about any other usages of that service, and you feel a lot more confident about making changes without something dumb slipping through the cracks and causing bugs in production.

This confidence generally lends itself to less fear of change and more willingness to refactor, which leads to a better/cleaner codebase.

Aside from that, I love the JSDoc comments showing up as you type, especially if you're working on a team in which you may not know 100% what everyone has worked on.

Other features I use every day and love:

-automatic/generated import statements

-type definitions for libraries (most have solid documentation)

-control-flow logic checking (you'll find more bugs than you think with this and it encourages more defensive programming)

-transpiling down to support older browsers (babel does this too but it's nice to have it built in)

Edit: I forgot to go into the "cons" list here.

-there's some finagling you'll have to do with some of the more poorly-written npm packages that strap themselves onto globals

-there's a slight learning curve

-you'll require a build step (with es6 if you're targeting es6-only browsers you can deploy just static files, but most people use webpack/babel anyway for older browser support and other things webpack gives you like bundling/minification/etc)


> you'll require a build step

I'd like to note that this is done automatically in Visual Studio 2015 and on. You just save your .ts file and VS will create the .js file.


While IDE transforms can be handy when getting started with small projects, you cannot use them for automated builds (projects with multiple contributors, continuous integration). Any serious project using TS does indeed require a build step.


As much as I will fairly praise Visual Studio, thanks for pointing out this automatic generation feature

I'm not by nature keen on automatic behaviour, or files appearing wherever, and though I visited this story simply to check in on the state of a language I know less than I want about, I'm certain that I would want a proper build step even for tinkering, once I start in earnest. I've long been enthusiastic about TypeScript especially, but from a distance, unable to allocate time to take it seriously enough.

I think the state of js and environment is now at a point that, in my view at least, I should not begin the smallest project without a deep dive into the state of the language. I see things moving so fast, that - at least in my workplace where we've had teams stick together for years commonly (partnership!) - it would suck to find oneself misdirected by a aggressive assumption, or find oneself in a unloved cul - de - sac of dependencies.

Tl;dr js is IMO at a place where the pay off for deeply studying the state of the language, is substantial while risk of not deeply groking js are rising fast.

Personally, I think I shall better resort to getting a new shelf of good books, for my needs, but I do believe the risk reward is looking hairy for any casual users. (or hurried business management, in particular)

I'm a little surprised, given my understanding the impression I had of ts is the very broad aim is to reduce your error in code, (type safety only part of that) that VS will encourage casual / random deployments like this. I can't decide if it's a occasional convenience quite suited to weekend js ciders like me, or a omitted formality that I feel encourages poor or slack habits.

Funny thing is, I never once thought of firing up VS to write JavaScript before now. I have no need, but I'm just displaying my age when I note that visually my mind thinks of early Netscape view source spelunking and text editors, not a actual IDE and build system.

What keeps me, well into a fourth decade of programming, from using JavaScript I think is only the fact that I totally phase out at the state of the tool chain for js. My mind blanks. But there's so much to like, using js, that i hope it's not abandoned by time I get to really learning it. (forgive my humour, but my first real computing experience was on a Symbolics 3650, then spanking new. Last week wanting to show a friend what one looked like, I found kids veritably boarding them! (sorry for the kids part, but it's nuts I found such phrases creeping up on me, I'm lucky in looking less than my years, but when did I start saying things like "the kids are doing x"? I want to know what causes this, and if there's a cure!)

Edit: Typos, minor clarity


The killer feature of Typescript is being able to model data. Most serious bugs I see in JS applications are because somebody serializes something from JSON, passes it around, and somebody somewhere makes incorrect assumptions about the data. Being able to type my models, Redux state, config objects, etc is a huge boost to developer productivity and maintainability.


^ all of which is of course available in Flow as well (in case OP got the wrong idea.)


Isn't that rather more fundamentally a documentation failure? Or communication failure, if data producers are expected to signal protocols where you work. Else a formality oversight for the data consumer developer to not seek documents and check your specs?

True, it _results in a bug. But when bug count gets high, and I see a noticeable percent originating from slacking habits, I start prowling to find who's been pulling too much overtime or something family is tiring them out. Nine out of ten times, it's someone who needs only firm advice to look after themselves better. Where I work age skews much higher than SV norms, so young children and other delights (not /s at all) have notable impact on code quality.


Not really. There's intrinsic value in being able to type a variable name and see all it's properties without having to look up documentation -- especially if it's code you're not familiar with. One less thing you have to balance in your head.


Very good point.

I quite commonly get a wood<>trees occlusion, when I'm thinking through my own habits, to visualize the world. I've just made documentation such a important part of my working life that I am constantly thinking through that structure. It began with a prospective business partner trying to blackmail my company in part by withholding key metadata for a important deal. The deal that founded my company, in fact. I know I was scarred badly by that. And this was a important friends, ten years my senior, without whose advice I would have..i don't know what other path... So I made self documenting a whole schedule in the partnership. Forget living off a LP interest in retirement, if you pull a stunt like the one that nearly bankrupted us before we started. (unlimited liability! We are since a limited partnership, but the fact we were a general partnership actually saved our houses on that first deal. The customer CEO actually noticed our names as one does put them on the letter head. Suddenly calls were made, subsidiary directors were gotten at home to listen up... Our customer CEO sussed how much we had on the line. The world changed in a instant. Not a small customer the kind you think might cate, either, DAX30! Edit to say I doubt any but a German boss would spot a partnership firm by letter head. &co KG is a very common incorporation form, UK L.P. also permits a limited entity as gp. UK lp can be domiciled wherever you like, too. If anyone will be helped by any experience i might offer, just drop me a line, I believe some of our long observations could have genuine assistive value for starting ventures. Specifically for any non UK nationals still wanting a post Brexit presence at minimum exposure. Banking for these partnerships can be tricky, or you may simply be blanked by confused staff, but I've has good experience i can relate if you need to bank in the UK for a project. N.b. UK L.P.s are not taxed at the corporate level, only your personal income can be taxed. The potential for compounding gains when yours small and growing, is nothing to be sniffed at)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: