Live data from Hacker News

JavaScript libraries should be written in TypeScript

staltz.com

21–30 of 285 posts

Re: JavaScript libraries should be written in TypeScript

#22
I've been porting over a reasonably sized project to Typescript for about a year now, well worth it.

Most of the time, the change is just to rename the file to `.ts`. Sometimes you have to change things because (surprise!) there was a bug.

The biggest painpoint is that you usually have to go pick up some type definition files from DefinitelyTyped for third party libs, but it's well worth it. Second biggest painpoint is type signatures (depending on the context, writing out types/definitions can be subtly different... or maybe I'm doing something wrong).

To anyone who's considering moving their JS stuff to Typescript but have hit some issues, please feel free to ask me. I really think it's a plus for sanity when writing JS.

Re: JavaScript libraries should be written in TypeScript

#23

I still run into libraries written in Coffeescript, and hate it when I do, because I don't use it and have a hard time following it. Javascript libraries should be written in Javascript. Worship the one true God!

Except this really isn't an issue for TypeScript, it reads that close to JavaScript.

Re: JavaScript libraries should be written in TypeScript

#24
post #7
post #3

Earlier quoted context omitted.

What's a "big" JavaScript library? How do you know how widely adopted your JavaScript library will be?

Regardless, it's difficult to think of any situation where a All _______ should use _______ is really justified.

All APIs need good documentation to be good APIs. If you're not providing good documentation with your API you're doing your users/consumers a disservice. Using a tool (TypeScript/Flow/whatever) to ease the pain of providing that documentation is in the best interests of an API developer since it reduces the friction of having to write the documentation by hand. Also, in this case, good documentation is not just documentation for the programmer that is consuming the API, but also the IDE within which the API is being consumed.

I'd say in this situation the title is justified.

Re: JavaScript libraries should be written in TypeScript

#26
post #10
post #5

And then new transpiler language appears, with "real" type system, not java-grade. And everyone stops using typescript, treating it as outdated technology.

It already appeared, and is called Purescript. It's great, and it's about as likely to gain traction as Haskell.

>it's about as likely to gain traction as Haskell

So rather unlikely?

Haskell has a JavaScript compiler as well, by the way (GHCJS).

Re: JavaScript libraries should be written in TypeScript

#27
post #7
post #3

Earlier quoted context omitted.

What's a "big" JavaScript library? How do you know how widely adopted your JavaScript library will be?

Regardless, it's difficult to think of any situation where a All _______ should use _______ is really justified.

All libraries should use input validation to avoid RCE and other attacks

All software that handles sensitive data should use transport encryption & encryption at rest

All software that uses encryption should use thoroughly vetted professional crypto

All computer users should use backup software

Re: JavaScript libraries should be written in TypeScript

#30
post #14

Starts off with: > Typed vs dynamic is a rather controversial topic, so I’m not trying to spark that discussion all over again. Goes on to explain that typed is betterer... The article doesn't really offer up any real arguments as to why you should specifically use TypeScript, but really just says typed is nice and everyone lints anyway (not true) so the step up to a type system really isn't that big of a deal (also…

The point the author is trying to make is that all Javascript libraries should be annotated with types. Not necessarily Typescript, but that's the popular choice right now.
Post reply on HN