Live data from Hacker News

JavaScript libraries should be written in TypeScript

staltz.com

31–40 of 285 posts

Re: JavaScript libraries should be written in TypeScript

#31
post #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.

It reads closely to JavaScript. But it is not.

Re: JavaScript libraries should be written in TypeScript

#32
Exact same arguments that I use when arguing that any software above a certain complexity level and intended for a long life and maintenance should be written in a strongly typed language with working generics system.

Seems ironic that JS community is starting to come around to that finally.

Re: JavaScript libraries should be written in TypeScript

#33
post #6

Or at the very least, library documentation really needs to clearly specify the types of parameters and return values. I'm positively surprised when I come across a JavaScript API whose documentation actually specifies this very basic information. Coming from the static typing world, it's astounding...

Yes. And, having worked with typescript, its quite annoying how poor most typings files are that you get from the definitelytyped repository. It's better than nothing, but they are unversioned (so always behind) and often very incomplete.

I agree with the author: types are there anyway, typescript seems to work well enough and has traction now, so please, if you write a library: add those type annotations bottom-up in the library and let typescript generate a nice .d.ts declaration file and standardized module stub around that final javascript library.

Re: JavaScript libraries should be written in TypeScript

#38

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!

Typescript isn't all that differentiable from ES6. While I'm generally on the vanilla train, feeling fairly compelled to use it when messing around with angular2 has made me very much appreciate it. Change your .js filename to .ts and it will still run, which makes the typing just an added bonus.

Re: JavaScript libraries should be written in TypeScript

#39
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…

Context matters. Some people, while writing their own application code, find types to be annoying, a nuisance, or whatever. That's a personal (or team) decision.

This article is targeted at authors and maintainers of high-adoption libraries. It says so right in the second paragraph.

And, frankly (speaking as someone with experience on this topic), he's right. Maybe static isn't always the answer, but in the context of high-adoption libraries, a little bit of effort to improve clarity and strictness is a huge lever for cutting down on wasted time of thousands of developers everywhere.

> The article doesn't really offer up any real arguments as to why you should specifically use TypeScript

Did you read it? He offers the Git/Mercurial comparison of TypeScript's growing popularity.

Re: JavaScript libraries should be written in TypeScript

#40
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…

I may choose not to document my code or not to test it - because it's just a one-time script, because it's going to be thrown away soon, because all my coworkers know what the code does... It's more than debatable of course, but it happens a lot in practice. However, if I write a piece of code that will be re-used a lot (inside my company, by friends...), I will do more of that (tests, documentation). I expect the same from libraries authors, whose explicit goal is to be re-used by others. The author's point is that typings is similar to tests and documentation - if you want people to use your projects, typings will help them (it actually serves as a good start for tests - catching bugs that cause compilers errors / warnings - and documentation - what your functions accepts is a very good start), and it adds eg. autocompletion / 'go to definition'. As a user, feel free to use Typescript or not. As a library author, help your users by using types.
Post reply on HN