News for hackers. Stuff that matters.
Re:TypeScript Won by koolba on Wednesday April 27, 2016 @10:37AM (#11580768)
Does anyone here have bad things to say about TypeScript?

I haven't used it for any large projects yet (couple toy ones) but seems pretty legit. Based on my anecdata, people who have used it at scale seems to like it.

I can't tell if that's because they're still in the honeymoon phase or if it really is a step forward for the long term.

Re:TypeScript Won by saosebastiao on Wednesday April 27, 2016 @10:48AM (#11580865)
In terms of Javascript targeting languages, Typescript has been the only one that hasn't made me want to murder a thousand baby seals. The build system is fast and easily understood, the typing makes refactoring so much easier, and in probably its biggest win, I can read a Javascript tutorial and trivially write the same thing in Typescript.

As a language, though, it still leaves a lot to be desired. Things like type guards and null annotations are like the methadone to the vastly more addictive pattern matching and options that I can no longer live without, and promises/callbacks are vastly inferior to futures. I would rather use Scala.js or Elm, but the ecosystems pale in comparison and trying to work in what is effectively an abstraction layer (and leaky at that) makes life really difficult. So I stick with Typescript.

Re:TypeScript Won by woah on Wednesday April 27, 2016 @11:48AM (#11581489)
Have you tried a async/await?
Re:TypeScript Won by softawre on Wednesday April 27, 2016 @12:47PM (#11582133)
async/await isn't in TypeScript yet, if that's what you were implying. It will be though (and obviously is part of babel if you choose the right pieces).
Re:TypeScript Won by billti on Wednesday April 27, 2016 @01:11PM (#11582339)
async/await has been in TypeScript for a while, but currently depend on generators, so don't down-level to <= ES5 emit (that work is in progress).

With the latest Node releases and modern browsers supporting generators today, you can target ES6 and use async/await today if you can target those environments.

https://blogs.msdn.microsoft.com/typescript/2015/11/03/what-...

Re:TypeScript Won by jdmichal on Wednesday April 27, 2016 @10:50AM (#11580880)
Top-level types can be permanently shadowed. For instance, if I name a type "Date" within a namespace, then every file within that namespace or a sub-namespace will no longer be able to access the JavaScript native Date type. This also apparently isn't something they're inclined to fix. [0]

The tsconfig.json file does not allow for glob-type inclusion of files, or even inclusion of directories. However, you can exclude entire directories. So if I want to simply compile everything in the "src" directory, my best option is to exclude every other directory.

[0] https://github.com/Microsoft/TypeScript/issues/983

Re:TypeScript Won by emodendroket on Wednesday April 27, 2016 @12:48PM (#11582136)
Isn't this kind of inherent to the JS model? I mean I guess you could rewrite the names of types at compilation but that would create other problems
Re:TypeScript Won by jdmichal on Wednesday April 27, 2016 @01:42PM (#11582645)
No, because I'm shadowing the type, not overwriting it.

JS doesn't have namespace scoping, and therefore everything has to be explicitly scoped. So if I create `my.awesome.Date`, just `Date` means JavaScript's `Date`, and I have to put `my.awesome.Date` to get the new type. Typescript adds namespaces and scoping rules, so that anything in the `my.awesome` namespace or any namespace below it will see `Date` as `my.awesome.Date`. And there's no way to explicitly reference the global scope, so within those namespaces the new type completely and irrevocably shadows the original JavaScript type.

Also in JavaScript, unless I overwrite the original `Date` type, I can always explicitly scope it by saying `window.Date`. But TypeScript doesn't define `Date` within the `window` type, so I can't use that out either.

Re:TypeScript Won by WorldMaker on Wednesday April 27, 2016 @01:58PM (#11582837)
Typescript's following the usual JS scope closure rules: the namespace syntax is sugar for the usual sort of JS "IIFE" object pattern, which you should be able to plainly see in the transpiled output.

Because Date is a data type, not every browser may attach `Date` to the global `window` object. I can't think of one that does not, but it's one of those cases where JS has always been ambiguous.

That said, Typescript is more than happy to let you `(<any>window).Date` assert your way to that global. Or if you feel particularly strongly about this, you could in increasing order of strength of opinion: 1) add .d.ts file somewhere augment window yourself with Date, 2) fork the lib.d.ts and use your own instead of the default, 3) send a PR to Typescript adding it to the default lib.d.ts and see if they have a stronger reason for it not being there beyond it just being ambiguous in the JS language/spec/library.

Re:TypeScript Won by jdmichal on Wednesday April 27, 2016 @02:26PM (#11583152)
> Typescript's following the usual JS scope closure rules: the namespace syntax is sugar for the usual sort of JS "IIFE" object pattern, which you should be able to plainly see in the transpiled output.

Yes, and in the transpiled output I will see `Date` turned into `my.awesome.Date` for files within the namespace scope. As I said, JavaScript is always explicitly scoped, so unless you shadow it with a local variable or overwrite the original, you can always access it. So I could easily write `my.awesome.Date` in JavaScript without shadowing the native `Date`, but I cannot do that in TypeScript because of the namespace scoping rules it adds. Which, pains of using TypeScript being the original prompt, seemed quite relevant.

Re:TypeScript Won by WorldMaker on Wednesday April 27, 2016 @01:35PM (#11582587)
Typescript's job is to add safeties to a lot of the JS footguns, but there are a lot of them if you are not careful, and also, even with a safety in place, some people just want to shoot themselves in the foot.
Re:TypeScript Won by Keats on Wednesday April 27, 2016 @11:12AM (#11581090)
The type system is not that great and inference is quite limited. Definitions are not always existent or up to date and a single repo like definitelytyped is a terrible way to manage all the definitions.

The above sounds negative but TS is still the best bet right now imo. Some people will prefer Elm or Purescript for better type systems but I like staying close to JS.

Re:TypeScript Won by d1plo1d on Wednesday April 27, 2016 @11:28AM (#11581250)
Personally, I'm more excited about Flow because it introduces a modern type system into ES6/ESNext without me having to sacrifice Babel.

With regards to types: TypeScript has only recently added support for any kind of Algebraic Data Types whereas Flow was built upon Unions and Intersections from day one. That to me speaks to their priorities.

Re:TypeScript Won by softawre on Wednesday April 27, 2016 @12:49PM (#11582150)
Unions were added in TS 1.4, over a year ago.

https://blogs.msdn.microsoft.com/typescript/2015/01/16/annou...

Re:TypeScript Won by WorldMaker on Wednesday April 27, 2016 @01:45PM (#11582684)
Also, Intersections were added in TS 1.6, last year:

https://blogs.msdn.microsoft.com/typescript/2015/09/16/annou...

They seem to be moving at a decent, agile pace to improving/expanding upon the algebraic sides of the type system.

Re:TypeScript Won by d1plo1d on Wednesday April 27, 2016 @05:50PM (#11584862)
Yup, I was definitely wrong on that one. Sorry about that.

Thank you for correcting me.

Re:TypeScript Won by WorldMaker on Thursday April 28, 2016 @10:53AM (#11589280)
Next up on the roadmap, Typescript is working to add opt-in strict null and undefined checking which is probably the last area where Flow's type system is particularly better than Typescript's.

(It will be opt-in as Typescript follows a rule of increasing strictness via compile options to support the spectrum of JS needs, but also as it will not be entirely backward compatible with existing type definition files and will need some effort among typings authors.)

Re:TypeScript Won by Keats on Wednesday April 27, 2016 @01:05PM (#11582284)
The fact that Flow doesn't work on Windows is a big limitation.

I prefer the idea of Flow as well but tooling and community is not there yet

Re:TypeScript Won by mercurial on Wednesday April 27, 2016 @01:14PM (#11582366)
There are occasionally Windows builds by the OCamlPro people popping up.

The fact that last time I checked, it wasn't able to consume TSD signatures from third-party libraries (or offer an equivalent system with a significant amount of libraries) is a much bigger issue IMHO.

Re:TypeScript Won by d1plo1d on Wednesday April 27, 2016 @06:01PM (#11584937)
Not terribly related but I am starting to see this as a pattern on the internet:

When I bring up the latest and greatest (eg. Flow) it doesn't actually work on Windows because Windows is as I see it an after-thought for a lot of the Open Source world.

But I've brought up this exact problem (the lag in tooling) to .Net/Windows devs before and they've told me I'm wrong and that they've got all the latest and greatest dev tooling like everyone else.

Re:TypeScript Won by WorldMaker on Wednesday April 27, 2016 @01:41PM (#11582641)
Typings uses an actual package management approach to type definition management and makes it easier to support repositories specific to a package definition and versioning typing definitions in synchronization with their upstream packages. Typings is particularly great for projects using NPM and/or JSPM packages. It's definitely time to move beyond DefinitelyTyped as the single point of failure and giant repo of doom.
Re:TypeScript Won by agd on Wednesday April 27, 2016 @11:00AM (#11580980)
The things missing for me are:

1. partial application (bind is typed as 'any')

2. sum type destructuring

3. issues with recursive type definitions

But the Typescript team add new features very quickly so I wouldn't be surprised if these issues are solved in the future.

Re:TypeScript Won by ryan-allen on Wednesday April 27, 2016 @10:54AM (#11580924)
I used it very heavily and exclusively for about 3 months. I'm not writing it day to day now but it was like having super powers in comparison to writing JS or Coffee.

I was using Visual Studio Community so I had all the benefits of intellisense (which is a big benefit), and I was able to manage a fairly complicated bespoke canvas thingo that suffered a few major refactorings - which I was able to perform with confidence due to the type checker.

The massive list of bundled typings and 3rd party typings makes it much quicker to pick up a new API or remind yourself of one you haven't used for a while.

I now write C# day to day and I find I don't spend the majority of my day alt-tabbing to and from documentation web pages as a result.

So... any bad things to say? None at all off the top of my head. I'm a huge convert, and not because 'it's nice' or 'it's pretty' but because it's like wearing the Iron Man suit when it comes to programming. It's helped me be more productive on non-trivial projects.

Re:TypeScript Won by nkohari on Wednesday April 27, 2016 @10:55AM (#11580930)
I love TypeScript, and after spending a few years writing JavaScript and CoffeeScript, I've switched to using TypeScript whenever I possibly can. The only bad thing that I can say about it is that the management of type definition (.d.ts) files for external libraries can be a bit of a pain, even using tsd. That's less an indictment of the way TS works, and more of the tooling around it.
Re:TypeScript Won by corysama on Wednesday April 27, 2016 @10:54AM (#11580918)
The only complaint I've heard is that TS makes JS feel more like C#. Lots of people would say that's a good thing. But, some people really appreciate the dynamic nature of JS.
Re:TypeScript Won by ryan-allen on Wednesday April 27, 2016 @10:57AM (#11580947)
In typescript the types are optional, so if you omit types it'll look very much like ES6.

You can mix and match dynamic stuff with Typescript, depending on your compiler options, it'll treat non-typed things as if you were writing regular JS.

I always turned on 'do not allow 'any' types' because I wanted everything typed.

As far as C#... there are enough minor differences for it to be rather annoying if you have to jump back and forth every second day. C# is vastly more powerful and convenient as a language to Typescript, though. I'd write C# in the browser if it were a de-facto option, and I used to write and love Ruby. C# has all the functional stuff I doted over in Ruby, and it's all typesafe!

Re:TypeScript Won by WorldMaker on Wednesday April 27, 2016 @01:49PM (#11582728)
Furthermore you can give Typescript the allowJS: true compiler option in recent versions and literally mix and match pure JS files and Typescript files in the same "project".
Re:TypeScript Won by jkrems on Wednesday April 27, 2016 @12:32PM (#11581973)
TypeScript's type system is "occasionally typed". E.g. in trivial, C#/Java-style code it works well. And even there it falls back to `any` way too often (and it can become hard to find out way). Flow's type system is designed with modern, more functional style in mind and didn't fail me yet.
Re:TypeScript Won by spion on Wednesday April 27, 2016 @03:22PM (#11583681)
Suggestion that solves your problem: don't use TypeScript without "noImplicitAny"
Re:TypeScript Won by Bahamut on Wednesday April 27, 2016 @11:01AM (#11580993)
The type definitions for some libraries aren't super fleshed out, which prevents you from doing some of the optimal styles possible with those libraries. I ran into problems with both lodash and ramda with TypeScript so far.

Other than those nuisances, I've grown to like using TypeScript a lot.

Re:TypeScript Won by akavi on Wednesday April 27, 2016 @11:29AM (#11581259)
The ability to programmatically generate methods/classes can be really powerful and, as far as I can tell, impossible with Typescript (and most statically typed languages).

Back in my Backbone + CoffeeScript days, I reimplemented Rails style has_many/belongs_to "class methods" on Backbone.Model, and it was incredibly useful. But would've been doubly so if I could have had it statically checked somehow.

Re:TypeScript Won by mordocai on Wednesday April 27, 2016 @11:33AM (#11581310)
I don't know if it is possible in any practically used statically typed languages, but I can think of nothing that would prevent you from doing metaprogramming in a statically typed language on a theoretical basis. It might be a bit hard to implement, but I think it should be perfectly possible.
Re:TypeScript Won by emodendroket on Wednesday April 27, 2016 @12:47PM (#11582124)
For small projects with little client-side code it's more trouble than it's worth. But no, if you're doing serious JS development I think it's worth seriously considering.
Re:TypeScript Won by lmm on Wednesday April 27, 2016 @10:54AM (#11580921)
Structural is worse than nominal. The types are unsound even without "any" because arrays are bivariant. There are no HKTs.
Re:TypeScript Won by spion on Wednesday April 27, 2016 @11:51AM (#11581524)
Structural is not worse than nominal. Nominal types are mostly a lie, and in the case of JS and package managers / module systems like npm / node's, they are a non-starter.

Arrays are no longer bivariant, and haven't been for at least a year. They are still covariant unfortunately.

Re:TypeScript Won by jackweirdy on Wednesday April 27, 2016 @10:58AM (#11580952)
It has a terrible type system
Re:TypeScript Won by draw_down on Wednesday April 27, 2016 @11:26AM (#11581223)
Like other compile-to-JS languages such as coffeescript, I don't think it has enough to offer over plain JS to justify its existence. Coffeescript was great because it drove a bunch of language features into consideration for ES6, but actually writing in it seemed like more pain than it was worth.

Consider being in the situation of being in charge of a large coffeescript codebase, today. No thank you.

Re:TypeScript Won by drumdance on Wednesday April 27, 2016 @12:36PM (#11582016)
Funny, I feel the exact opposite about CoffeeScript, but maybe I'm not using enough advanced features.

In particular I like how readable and clean CoffeeScript is when you have a long series of callbacks.