

Working on TypeScript 0.9: Generics, Overload on Constants and Performance - yread
http://blogs.msdn.com/b/typescript/archive/2013/03/25/working-on-typescript-0-9-generics-overload-on-constants-and-compiler-performance.aspx

======
SideburnsOfDoom
I like strongly typed languages and generics, but I see generics as adding a
complexity to a type system in order to get around the limitations of the type
system.

Javascript, on the other hand, is duck-typed. Everything is the equivalent of
generic already. Adding generics to the Javascript wrapper feels awkward and
overcomplex and somehow suggests that a point has been missed. Perhaps you
feel differently?

~~~
AndrewDucker
How do you guarantee that what is added to a list (for instance) is a Dog, and
not a Cat?

If you want strongly typed language support (and I do), then generics make it
vastly easier to write maintainable code.

A generic doesn't mean "anything goes" - it means "You will definitely get the
thing that you specified".

~~~
SideburnsOfDoom
In Javascript or any other duck-typed language, you don't have that guarantee.

You don't actually care that it's a Dog BTW, just that it has a method called
Bark(), if that's what you call on it.

You make sure that your code only puts dog-like objects into the list, either
by writing tests or by reading the code and praying. But the system of putting
objects into lists is really, really simple.

I see the benefit of strong typing and I use it all the time. Generics are an
epicycle that IMHO sits poorly with JavaScript.

~~~
AndrewDucker
Exactly. This is _not_ Javascript. It's Typescript, which compiles into
Javascript, but adds in guarantees that, for instance, what I'm getting _is_ a
dog.

~~~
SideburnsOfDoom
Typescript is not JavaScript, but all JavaScript is TypeScript, including
JavaScript that works as discussed above. It's just a bit funny that in
Typescript are both a language that benefits from having generics and a
language that doesn't need them.

------
bokchoi
The overload on constants pattern matching is an interesting feature.

------
domlebo70
How are they planning on structuring the collections methods? Is map going to
be on Arrays, and Maps and Lists etc? Or will they utilize some sort of
typeclass approach and have them as modular as possible?

~~~
asolove
They aren't planning to add collection methods, just to provide a means for
existing methods like Array#map and Array#filter to be typed. Right now there
is no way to write a type signature that says, given an array of numbers and a
function from numbers to strings, Array#map returns an array of strings. This
allows that.

------
spo81rty
Looks like some great improvements. In some ways having to declare the
generics may slow down coding but will improve quality greatly.

------
camus
meh. While some constructs are great (class , modules , ...) some others dont
make sense at all, unless you are using Visual Studio. Is typescript a
javascript for Visual Studio or a language you can really use without MS tools
? Also the fact that you cant compile to 1 file automatically all your scripts
and you need either AMD or Common JS defeats the purpose of having modules for
client side scripting.

~~~
lucian1900
It's possible to instruct tsc to compile into called-closure style modules,
then concatenate them if you really want that.

~~~
seandhi
That is exactly what we are doing with an in-house TypeScript framework that
we have written. The compiler checks the dependencies recursively and then
concatenates them in a single file. It is careful not to duplicate
dependencies, too.

