Live data from Hacker News

JavaScript libraries should be written in TypeScript

staltz.com

61–70 of 285 posts

Re: JavaScript libraries should be written in TypeScript

#61
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.

But the typescript type definitions will still be useful. See e.g. https://github.com/sjrd/scala-js-ts-importer

Re: JavaScript libraries should be written in TypeScript

#63

Absolutely not. This is the opposite of what you should do in my opinion. If you're writing an API to be consumed in language X then you need to write the API itself in language X. This will help you capture and handle edge cases, language idiosyncrasies and other similar issues the way you want. Using a different language that gets transpiled into a target language also increases your surface area for bugs because n…

This reads like knee-jerk reaction from someone who's never tried TypeScript.

Re: JavaScript libraries should be written in TypeScript

#66
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.

Are you arguing in favor of everyone sticking to the lowest common denominator technology just because the pace of change is too quick? I would wager that things are changing so much exactly because of this reluctance to adopt new developments at scale. It's a vicious cycle, to be sure, but plain vanilla JavaScript everywhere can't possibly be the savior!

Re: JavaScript libraries should be written in TypeScript

#67

Absolutely not. This is the opposite of what you should do in my opinion. If you're writing an API to be consumed in language X then you need to write the API itself in language X. This will help you capture and handle edge cases, language idiosyncrasies and other similar issues the way you want. Using a different language that gets transpiled into a target language also increases your surface area for bugs because n…

I can absolutely understand that coming from coffeescript (optional parentheses resolution... yikes).

But TypeScript is basically "Javascript + types + ES6". They call it an "erasing compiler" because it's not meant to do much but remove types/make ES6 code work with ES5.

There is one gotcha in name resolution when you're working in modules (if you are in a module a.b, and a.c exists, then c will automatically refer to a.c, even if a global c exists). But that usually gets caught by the type system. Lot less issues than coffeescript IMO

Re: JavaScript libraries should be written in TypeScript

#68

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!

Simple solution - offer the compiled file in the library. Everyone wins.

Re: JavaScript libraries should be written in TypeScript

#69

With WebAssembly making its rounds it would be cool if Javascript libraries are able to be written in C/C++ or other lower-level languages then exposed via an API. That way a lot of algorithms can be shared with native code-bases too.

That could more easily be accomplished if they had chosen a proper bytecode, like LLVM, even JVM. It's still possible, but WebAssembly is just a Javascript AST.

Re: JavaScript libraries should be written in TypeScript

#70

Absolutely not. This is the opposite of what you should do in my opinion. If you're writing an API to be consumed in language X then you need to write the API itself in language X. This will help you capture and handle edge cases, language idiosyncrasies and other similar issues the way you want. Using a different language that gets transpiled into a target language also increases your surface area for bugs because n…

If it can't be compiled to JavaScript reliably then how do you expect it to be compiled to WebAssembly reliably?
Post reply on HN