Live data from Hacker News

JavaScript libraries should be written in TypeScript

staltz.com

231–240 of 285 posts

Re: JavaScript libraries should be written in TypeScript

#231
post #35

This is akin to saying "Every C++ library should be written in Objective C." EDIT: Hey people down voting me; it literally is the same. C++ is a standard, JS is a standard. TypeScript is (like Objective-C) a compatible alternative.

Absolutely not. Objective-C started out as a superset for C. Emphasis on 'started out'. It has nothing to do with C++. You can combine the two of them but they are hardly compatible. Messaging on the side of Objective-C vs. custom operators on the side of C++ being just one example.

Yeah and TypeScript has Types and JS doesn't. So, there's incompatibilities there too. Granted, the relationship is backwards so maybe I should have reversed the comparison, but it still stands. This was an asinine suggestion.

Re: JavaScript libraries should be written in TypeScript

#232

Earlier quoted context omitted.

You mean in TS? Yes. ∀ x: I can do x in JS → I can do x in TS But, let's assume for a second that you couldn't: this thread is about TS being future-proof. I.e.: ∃ x: I can do x in TS & I cannot do x in JS? No, false. This implies TS = JS. And that's the point: semantically, TS = JS.

OK, that's a good start. Is there a tool analogous to JSDoc for TypeScript that gathers the same docs without repeating the type info already in the code?

http://typedoc.io/ might be what you're looking for.

Re: JavaScript libraries should be written in TypeScript

#233
There's a big misconception that JS has zero typechecking. This is not true; rather, JS has dynamic typechecking. It turns out that when you're making an API for an external call, you will need to manually check the types of the incoming data anyway (and this is where I see 99% of JS type errors). This is something that JS is equipped to do fairly easily when necessary.

A typical type problem would be sending a float instead of an integer. Sending a float instead of a regex would not be a typical problem.Static types are necessary in less dynamic languages because they have multiple competing types which can't be distinguished otherwise (eg. all the integer subtypes) and they have structs/classes that cannot be dynamically modified. JS types are simple (number, object, string, etc) and very different in nature. In addition, this kind of error will be caught quite quickly with even the most rudimentary unit tests. Half-way decent docs where modules interact should solve the remaining issues. Running into type errors within the same file or two is probably symptomatic of a lack of composition.

Enter Typescript. It has one major positive in that it prevents some dynamic techniques that can tank performance (though performance graphing and reducing dynamism is probably a better solution). Because you cannot depend on everyone using typescript, all external APIs must STILL have dynamic type checking.

This leaves you with type checking within your own project. Typescript can be turned off anywhere a programmer wants making it unable to guarantee type safety. It adds a lot of extra typing and visual overhead. Unlike C# (where it gets it's type syntax inspiration), the types do nothing for the JIT because the JIT never sees them.

There's no reason for a modern type system to not be based on Hinley-Milner. There's no reason for 95% of typing to be inferred by the computer rather than forcing it to be typed out. There's no reason to use a system that's only good for the assembler when the assembler will never even see it.

Re: JavaScript libraries should be written in TypeScript

#234

Earlier quoted context omitted.

Are you implying that it's factually incorrect? Also, the word "silly" appeared in the BinaryIdiot's comment first. You have to be prepared for not exactly polite responses when you do something like this.

Incendiary language like "you obviously have no idea what you're talking about" is bad for the quality of your comment, and this entire discussion. Not everyone is capable of looking past personal attacks like yours. It is the first step to a flame war. You have something to say? Great. Just say it, no need to talk about how little the other person knows. Aside from "two wrongs don't make a right," do you really feel…

No, to be honest - and I really expected you to drop this argument, which is why I didn't bother elaborating earlier - it was an emotional response from my side. The first version of my previous comment didn't focus on the word "silly", it read something like this: "it may not be right to call the other person ignorant, but, for this particular person, it felt soooo good!"

Just as you say, we're human, which is why "not everyone is capable of looking past personal attacks". Moreover, what we regard as "personal attacks" varies from person to person. Personally, I felt insulted by the specific kind of ignorance displayed by BinaryIdiot in his posts in this thread.

I know I shouldn't have and I don't think the downvotes are undeserved. On the other hand, I obviously have my reasons for feeling that way; judging by the font color of many BinaryIdiot's posts I wasn't the only one.

I read through all the posts in this thread before posting. BinaryIdiot talking about how he experienced "transpiling languages" in the form of CoffeeScript and so he knows everything there is to them... That was excruciating. Him talking about compilation and compilation targets was similarly painful. One of the versions of my first reply to you read: "I've been hurt in enough ways and enough times [by people behaving like that] to develop a little bit of aggressiveness towards them."

In all honesty, the point about how compilers work was just an excuse. I suppose what I really wanted to do was to tell BinaryIdiot how wrong he is about some things, and how irritating it is for me personally (especially today!) to see him talking about programming languages, compilers, and whatnot without first investing any time on research.

Well, it's still wrong and I should have just ignored the whole thread.

Re: JavaScript libraries should be written in TypeScript

#235
post #63

Earlier quoted context omitted.

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

I've used it but never in a serious project. Like I said when it can be compiled into WebAssembly then count me in I'll certainly give it another shot. But until then I just don't want to deal with an, albiet probably rare but possible, transpiling bug. Plus there is huge value, in my opinion, in writing an API in the same language it's going to be consumed in. It lets me dogfood more effectively and write better, re…

Do you ever minify your JavaScript before deploying? How do you know there are no bugs in your minified?

Re: JavaScript libraries should be written in TypeScript

#236
post #63

Earlier quoted context omitted.

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

I've used it but never in a serious project. Like I said when it can be compiled into WebAssembly then count me in I'll certainly give it another shot. But until then I just don't want to deal with an, albiet probably rare but possible, transpiling bug. Plus there is huge value, in my opinion, in writing an API in the same language it's going to be consumed in. It lets me dogfood more effectively and write better, re…

Do you ever minify your JavaScript before deploying? How do you know there are no bugs in your minifier? (edit - typo)

Re: JavaScript libraries should be written in TypeScript

#237
post #225
post #208

I would use Typescript, but its type system isn't smart enough to handle the complexity of JS ecosystem. The other day I wanted to move my project to typescript, the first module needed ambient definition that didn't exist in Definitely Typed repo, it was quite annoying to create, and I am not even sure it's correct, then I wanted to type some parsed JSon that had a TYPE_NAME property with a string giving its type, i…

Flow is being ported to work on windows and there are now builds out there for it https://github.com/OCamlPro/flow & the binary downloads http://www.ocamlpro.com/pub/ocpwin/flow-builds/

Thanks, I know but it doesn't work really well with server setup sadly.

Re: JavaScript libraries should be written in TypeScript

#238

Earlier quoted context omitted.

Incendiary language like "you obviously have no idea what you're talking about" is bad for the quality of your comment, and this entire discussion. Not everyone is capable of looking past personal attacks like yours. It is the first step to a flame war. You have something to say? Great. Just say it, no need to talk about how little the other person knows. Aside from "two wrongs don't make a right," do you really feel…

No, to be honest - and I really expected you to drop this argument, which is why I didn't bother elaborating earlier - it was an emotional response from my side. The first version of my previous comment didn't focus on the word "silly", it read something like this: "it may not be right to call the other person ignorant, but, for this particular person, it felt soooo good!" Just as you say, we're human, which is why "…

Ok, I think you have a point and I blew the thing out of proportion. Sorry for that.

Re: JavaScript libraries should be written in TypeScript

#239
post #129

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…

TypeScript is ES6 with types, so it is not a different language at all.

Not true at all. TypeSript has ES6 modules and its own module syntax. I don't know if it has improved recently, but using ES6 modules in our TS was nearly impossible if using type definitions using the old module syntax.

Re: JavaScript libraries should be written in TypeScript

#240

> but transpiling it down into a language that isn't as type strict just seems silly to me You obviously have no idea what you're talking about. Almost all statically typed languages get compiled to something much less type-strict. This is one of the reasons for writing compilers in the first place! Case in point: Haskell gets compiled to assembler. You can't get a much bigger difference between typing disciplines th…

[deleted]
Post reply on HN