Live data from Hacker News

JavaScript libraries should be written in TypeScript

staltz.com

261–270 of 285 posts

Re: JavaScript libraries should be written in TypeScript

#261
post #256

Earlier quoted context omitted.

When in Rome, do as the Romans do. If you're programming in a dynamic language, there are things that you do that would not easily fly in a static language. Things like tests for truthiness. On first blush, from a static background, something like "var p = x && x.y && x.y.z || w;" look terrible, but they're pretty standard ways of cascading through different options without causing null pointer exceptions in a langua…

Sorry moron4hire but you are underestimating TS types system. You can write quite crazy expressions abusing Boolean operators and he successfully keeps the static type. You can also have different method overloads signatures as long as you have a more general implementation that does the dynamic checks at run-time manually. Most of the time you can use Union types anyway. The big collection of definition files for al…

Laziness is the root of computer science. There is no virtue in hard work for hard work's sake.

Re: JavaScript libraries should be written in TypeScript

#262
post #244

Earlier quoted context omitted.

My experience with Purescript/pulp was rather negative. Basic commands were throwing errors (pulp init IIRC) so I decided to not even consider it for anything serious.

The tooling is not perfect, that's absolutely true. I have to say though that any imperfections (which are going to get fixed anyway) are well worth it if you want a pure strongly typed language for the web. There's simply nothing better (except the full-blown Haskell-to-js compilers, like GHCJS and Haste of course). I recommend you try again and file a bug or look for help in irc if something breaks again (although…

My memory could be off (on which command failed). I think I still have the repo on my home machine, so I could re-visit and file a bug report. At the time I kept pursuing elm instead. Reports of better FFI with JS is why I had explored PureScript.

Re: JavaScript libraries should be written in TypeScript

#263

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

> You obviously have no idea what you're talking about.

This breaks the HN guidelines by calling names and turning an otherwise substantive (indeed, correct) comment into a personal attack. Please don't be nasty here, regardless of what the other person did or how mistaken they are. We detached this subthread from https://news.ycombinator.com/item?id=11297077 and marked it off-topic.

(Edit: I just noticed the discussion downthread— didn't mean to pile on.)

Re: JavaScript libraries should be written in TypeScript

#264

Earlier quoted context omitted.

Have you used TypeScript? Try it out for a month or two on a real project. It's the best thing that has happened to web development in recent years - it improves Javascript in a completely compatible and future proof way. The most amazing thing is that Microsoft created it. It's the polar opposite of Old Microsoft - standards are being followed (not subverted), it's simple pragmatic and has no lock-in.

I love Typescript, I do all my javascript coding via it. However, Though I wish it were, Typescript is NOT currently suitable for defining modules for external consumption. The problem comes down to no effective means of publishing the typings of your project and your project's dependencies. For example, if your project uses Promises, you might choose to include a definition of those promises, or (worse) reference a…

TypeScript has support for namespaces, and `import` gives you a lot of flexibility. If these aren't sufficient to handle the problem you describe, can you explain how? Can you post a link to the issue you are watching so we can see a better description of the problem you're running into?

Re: JavaScript libraries should be written in TypeScript

#265
post #23

Earlier quoted context omitted.

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

It's not about reading, it's about the tooling you need to set it up. JS initial strengh was ease of dev for beginers. Throw in a transpiler, a dependancy manager, a package manager, a bundler with FS watching, and source maps and what you got is wall for the very same type of dev that were producing all those fantastic jQuery plugins 10 years ago. And actually even for me. I do know how to install and use all those.…

you say "only one project out of 5 are [sic] big enough to justify it", and then complain that the perks that tooling provides aren't part of the core language. do you see the inconsistency there?

Re: JavaScript libraries should be written in TypeScript

#266
post #255

Earlier quoted context omitted.

I often use tagged union like interfaces in TS. It's definitly doable, but it might be a little more work than in Flow. For the definitions I do things like interface BaseInterface { TYPE_NAME: string }, interface DervicedInterface extends BaseInterface { ...content }. And to safely access the content of one or the other type I'm using user defined type guards like function isDerived(a: BaseInterface): a is DerivedIn…

Thanks, I didn't think of that, it's a little more work and error prone with functions and else/if code and less aesthetic than the switch/case that works with Flow, but I might restart my typing goal knowing that.

Yeah, the if/else cascades that you need when there are lots of cases are definitly not on the most elegant side. But maybe some support for type guards in combination with switch/case will follow. In can live with the current situation, because it isn't really better in most other programming languages without sum types (you mostly need some instanceof followed by a type cast).

Re: JavaScript libraries should be written in TypeScript

#267

Earlier quoted context omitted.

not sure what you're trying to say.

There are a lot of good JavaScript alternatives out there. This article sort of misses the point in what's good about alternatives existing - you can use any of them and expect decent interop with javascipt. A library in one is more exclusionary for all the other interests out there.

[deleted]

Re: JavaScript libraries should be written in TypeScript

#268

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…

Specifically regarding this discussion of typescript/javascript what are some edge cases and language idiosyncrasies problems you'd run into writing libraries in typescript?

Re: JavaScript libraries should be written in TypeScript

#269
post #232

Earlier quoted context omitted.

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.

Thanks. Also, some informative samples of what TypeScript itself looks like.

https://github.com/sebastian-lenz/typedoc/blob/master/src/li...

Re: JavaScript libraries should be written in TypeScript

#270
post #244

Earlier quoted context omitted.

The tooling is not perfect, that's absolutely true. I have to say though that any imperfections (which are going to get fixed anyway) are well worth it if you want a pure strongly typed language for the web. There's simply nothing better (except the full-blown Haskell-to-js compilers, like GHCJS and Haste of course). I recommend you try again and file a bug or look for help in irc if something breaks again (although…

My memory could be off (on which command failed). I think I still have the repo on my home machine, so I could re-visit and file a bug report. At the time I kept pursuing elm instead. Reports of better FFI with JS is why I had explored PureScript.

Update: The bug is with pulp server https://github.com/bodil/pulp/issues/133
Post reply on HN