News for hackers. Stuff that matters.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by madeofpalk on Tuesday March 02, 2021 @08:44AM (#26315214)
Typescript is hardly "new", it's fairly widely accepted now. It might be worth thinking "why do all these people enjoy using Typescript?".

or idk just say that no, its the kids that are wrong.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by airza on Tuesday March 02, 2021 @10:45AM (#26316463)
I myself am quite fond of it actually! I was initially suspicious of Node at first and of TS as well, but like the author, I eventually gave it a try and liked it a lot. (Probably after many of the pain points had been worked out!)
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by ForHackernews on Tuesday March 02, 2021 @08:48AM (#26315245)
I mean, Coffeescript was fairly widely used at its peak, and now it's all but dead.

Front-end fads are fickle. At least TypeScript has Microsoft backing it so they'll likely continue to support even if the rest of the webdev world moves on to the next shiny object.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by tenaciousDaniel on Tuesday March 02, 2021 @08:57AM (#26315331)
I also have fond memories of painstakingly converting hundreds of coffeescript files back to JS. There's something to be said for using the native language.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by runarberg on Tuesday March 02, 2021 @01:13PM (#26318372)
In my private projects I always write in JavaScript and provide static typing using JSDoc comments (which typescript can check). Then I run the type checker with `--noEmit`. I have yet to run into a problem with this approach.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by nullserver on Tuesday March 02, 2021 @11:42AM (#26317184)
Browser support and consistency got a lot better.

JavaScript was a minefield of compatibility problems. Many intentional, cough: Microsoft.

Jquery was awesome because it dealt with most of that

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by recursive on Tuesday March 02, 2021 @12:33PM (#26317852)
JQuery dealt with DOM and browser stuff. Coffeescript dealt with syntactic language stuff. I can't think of a case where Coffeescript helps with the same thing JQuery does, although it may exist.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by tenaciousDaniel on Tuesday March 02, 2021 @12:51PM (#26318075)
Yeah as best I can tell, Coffeescript was a thing because Ruby was very popular at the time, and some Ruby devs had to write JS but they wanted to write Ruby.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by wmil on Tuesday March 02, 2021 @10:06PM (#26324236)
I was never a fan of the Rubyisms in Coffeescript. But it's sad nothing else ever implemented the YAMLisms.

Typing up constants in Babel JS is so much uglier than it needs to be.

But Coffeescript also introduced things like arrow functions that bind `this` to JS. Transpiling to ES5 allowed JS to evolve.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by ForHackernews on Tuesday March 02, 2021 @02:30PM (#26319359)
I think everyone except JS devs wishes they could write something other than JS for the browser.

Maybe eventually with WebAssembly...

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by WorldMaker on Tuesday March 02, 2021 @03:17PM (#26320021)
That was definitely the case before ES2015. I think many of the non-JS devs that still hugely wish they could write something other than JS for the browser haven't kept up with ES2015+ nor Typescript. ES2015 is a much improved language and vanilla JS isn't painful anymore, especially with type="module" support now green enough in caniuse statistics that we can finally kill AMD and CommonJS for good in greenfield vanilla JS projects. The sky is quite sunny and ES2015+ is a better language than a lot of non-JS devs think JS is.

It will still be a while before all the brownfields in the larger ecosystem get cleaned up (if some of them ever do), but that's no longer a language problem, that's a a long tail ecosystem problem.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by tenaciousDaniel on Tuesday March 02, 2021 @04:31PM (#26321111)
Yup. I don't find myself using classes much, but some of the other new features remove the vast number of issues you tend to face.

Is scoping an issue for you? Just use arrow functions!

Is callback nesting an issue for you? Just use `async/await`!

I love it so much.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by recursive on Tuesday March 02, 2021 @05:13PM (#26321742)
I use classes a fair amount, but there's still some weird stuff in the language I'd take out if I could.

Sparse arrays, all object keys are strings (or symbols), crazy coercion rules, the existence of `null`, weird float vs int rules.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by runarberg on Tuesday March 02, 2021 @05:50PM (#26322234)
You can use `Map` instead of object which allows keys of any type, or typecheck your objects with `Record<K, V>` and let typescript warn you about any weirdness. Typescript can also warn you if you do some weird implicit coercion. You can typeguard against `null` (although I admit it is annoying, I just want to use an optional†). And if you really want to use integer types there is always `BigInt`.

---

†: I haven’t checked, but I bet there are some libraries out there that provide proper optionals using Proxy.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by recursive on Tuesday March 02, 2021 @07:24PM (#26323155)
I use BigInt often, but you can't (for example) do most substring operations with it, even though floating point indexes make no sense.

Map goes part of the way to what I want. But I really want to control which objects are considered equivalent keys, rather than being limited to reference equality.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by WorldMaker on Wednesday March 03, 2021 @01:34PM (#26332528)
There's a Stage 2 proposal before TC-39 to add immutable Record and Tuple types [1] which would be structurally compared and perfect for complex Map keys.

It's also easy enough to find or write quick simple Map wrappers that use a hash function on an object as keys when provided (either piggy-backing on the existing Object.prototype.valueOf, which always exists on every object and easily falls back to the reference-based current behavior, and expecting classes to have custom overrides for that, or using a Symbol named function of their own to avoid polluting own-property-keys/name clashes with other libraries).

[1] https://github.com/tc39/proposal-record-tuple

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by lmm on Tuesday March 02, 2021 @08:38PM (#26323648)
Scala.js actually works really well. Frontend people aren't very aware of it, but if you're a backend dev who just needs to write a bit of code that has to run in the browser then I highly recommend it.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by adav on Friday March 05, 2021 @11:26AM (#26358637)
Even as an engineer happiest in Scala almost forced to write Typescript, I'll be the first to admit that the Scala.js library is still a bit lacking in comparison for real world productivity.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by lmm on Sunday March 07, 2021 @08:50PM (#26381591)
I had exactly the opposite experience. I kept trying to make Typescript work and it just wouldn't, eventually resorted to Scala.js and found (to my shock) that everything just worked and there were far less random rough edges.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by adav on Monday March 08, 2021 @06:19PM (#26393011)
That’s great :) Scala.js has such potential. I hope that my next opportunity to try it out (versus TypeScript) will be a similar experience to yours!
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by mixedCase on Tuesday March 02, 2021 @10:57AM (#26316633)
CoffeeScript served a purpose, and was not a fad. It got deprecated by an ECMAScript that adapted most of the good parts.

TypeScript brought something good for the JS ecosystem (although Flow did it too, in a different way) and it doesn't look like anything will be able to replace it at what it does anytime soon.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by runarberg on Tuesday March 02, 2021 @01:17PM (#26318436)
I am really hoping TC-39 starts considering optional static types (similar to python), using a simpler syntax then TypeScript (e.g. no enums). However I don’t have high hopes they will any time soon.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by specialp on Tuesday March 02, 2021 @09:04AM (#26315410)
Coffeescript was a good thing when we only had ES5. In fact many of the things it championed made it into ES6 and beyond. I think with TypeScript it isn't just a shiny thing. If it does substantially change I believe it will be to break the forced compat with JS. As WebAssembly gets more adopted it will be possible to not have JS targets, and thus remove a lot of the weird JS things that have been kept for compatibility. Typescript has the gravity to continue.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by scrollaway on Tuesday March 02, 2021 @08:53AM (#26315301)
I don't think I've ever heard of any in-production, large apps in Coffeescript, even from when it was at its peak. I know of a handful of companies that tried it and even enjoyed it quite a bit but none of it was for mass consumption.

Typescript, meanwhile, is used for hugely popular apps, is used by very large companies, has Microsoft's full backing, etc.

The two are not comparable.

Edit: Clearly I'm misremembering its popularity.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by jitl on Tuesday March 02, 2021 @09:02AM (#26315384)
A significant portion of Airbnb was written in Coffeescript, including most of the complex app-like stuff used by hosts to manage listings and calendars.

We ported off of Coffeescript when ES6 and Babel came out, and you could start writing `class` and using `() => {...}` function expressions with lexical `this` scoping.

Coffeescript lost because it stood still next to the ecosystem and next to the new Ecmascript language standards, which obliviated its advantages. The only advantage Coffeescript had over ES6 was “some of your code is already written in it”.

Once Ecmascript formalizes a type system, we’ll see the same process happen with Typescript. But, I think it will be many years before that sort of feature is standardized. In the mean time, I’m happy to use Typescript today.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by ForHackernews on Tuesday March 02, 2021 @08:56AM (#26315328)
At one time, Dropbox and Github were all-in on Coffeescript e.g. https://web.archive.org/web/20130815075924/https://github.co...
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by ChrisLTD on Tuesday March 02, 2021 @08:57AM (#26315335)
Wasn’t CoffeeScript the preferred way to write JS in Ruby on Rails for years?
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by scrose on Tuesday March 02, 2021 @09:11AM (#26315468)
I think the Rails resource generators still default to creating Coffeescript files. I could be wrong though — I switch between Rails 4,5 and 6 projects right now. I’ve been on over a dozen Rails projects at different companies and only ever worked one project that used Coffeescript in production, and that was an app built pre-2010.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by nullserver on Tuesday March 02, 2021 @11:44AM (#26317205)
HAML and coffeescript.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by aendruk on Tuesday March 02, 2021 @12:31PM (#26317830)
I miss the elegance of Haml. Moving from an indented syntax for DOM literals to the likes of JSX felt like a step backwards.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by scrollaway on Wednesday March 03, 2021 @05:09AM (#26326591)
Maybe for you, but that is not a popular opinion. JSX's rigor is a breath of fresh air in a world that constantly generates low quality html due to loose constraints. HAML had those same problems.

JSX is kind of xml done "right". Differences between children and attributes in xml is very hard to grasp, but JSX has a much better defined structure to it and is super well suited to generate html because of that.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by aendruk on Wednesday March 03, 2021 @10:10AM (#26329298)
This sounds like an orthogonal point. (I agree with it, so it feels odd to see it presented as a rebuttal.) Surely an indented syntax could have rigor if we wanted it to?
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by scrollaway on Wednesday March 03, 2021 @10:30AM (#26329603)
Sure, if we wanted it to, but HAML wasn't that.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by aendruk on Wednesday March 03, 2021 @10:49AM (#26329938)
Yes.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by akavi on Tuesday March 02, 2021 @11:36AM (#26317115)
PagerDuty’s front end was 100% coffeescript until at least 2016
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by bananabreakfast on Tuesday March 02, 2021 @03:41PM (#26320337)
Square's entire merchant dashboard was in CoffeeScript. Half a million lines of code.

Took over a year to convert to ES6.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by gameswithgo on Tuesday March 02, 2021 @08:47AM (#26315237)
All the kids enjoyed using Javascript too. Language popularity is a bit of a random walk.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by baybal2 on Tuesday March 02, 2021 @08:54AM (#26315314)
Typescript is not accepted. How AngularJS stuck on 1.* is the best proof, and an illustration for the problem. Pretty serious people are working in Angular community, it's immensely popular in the enterprise webapp space, so I will not take the "Ah, it's just amateurs who are stuck there."

It adds to countless attempts of other transpiled *scripts to extend Javascript.

They, and Coffeescript in particular, are good historical references to what will happen to TS in a few years.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by arcturus17 on Tuesday March 02, 2021 @09:02AM (#26315376)
About 95% of React components I see in the wild are in TypeScript. The most rapidly growing JS backend framework (Nest) is in TS. Deno, the evolution of Node, is based on TS. Pretty much everything in the JavaScript OSS world has TS options or is based on TS.

I doubt Coffeescript ever saw this scale of adoption.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by pjmlp on Tuesday March 02, 2021 @09:55AM (#26315928)
We only use TypeScript on frameworks that make it a requirement, the language is starting to look like Haskell.

As much as I like Anders work, it is impossible to understand modern TypeScript without looking into tsconfig.json before looking into source code.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by zaccusl on Tuesday March 02, 2021 @12:38PM (#26317910)
I don't understand what the tsconfig has to do with understanding the source? Maybe when using different path resolving or different tsconfigs to compile test files vs. production files?

Many toolings make it so you don't even need to worry about the tsconfig anymore (though in reality it is very helpful to understand it).

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by pjmlp on Tuesday March 02, 2021 @03:34PM (#26320250)
To avoid breaking existing source bases, many features or corrections across the language versions are opt-in, so in some projects it looks like GHC feature pragmas.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by madeofpalk on Tuesday March 02, 2021 @12:54PM (#26318109)
This does not align with my experience of writing Typescript at multiple companies of varying sizes and open source projects.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by pjmlp on Tuesday March 02, 2021 @03:32PM (#26320229)
Lucky you for not having devs that would rather be using Haskell Lens and stuff like that.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by jogjayr on Tuesday March 02, 2021 @09:35AM (#26315713)
I wrote AngularJS 1.x in TypeScript in an enterprise application. Being "stuck there" ("there" meaning pure JS for Angular 1.x) is a choice.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by acemarke on Tuesday March 02, 2021 @12:00PM (#26317420)
I took over a legacy AngularJS 1.x MEAN app early last year. One of the first things I did was to convert it from using Gulp to building the client with Create-React-App's build tooling:

https://blog.isquaredsoftware.com/2020/03/codebase-conversio...

That unlocked the ability to add React and TypeScript code embedded directly in the existing AngularJS UI, using the `react2angular` library, as a short-term migration approach. I was also able to migrate some of our existing AngularJS controllers and client logic to TS to get a bit more safety.

Since then, I've set up a new Next.js subproject that sits behind the existing Express app server, and was able to show content from Next by inserting iframes into the AngularJS templates and proxying those URLs from the Express app to the Next app. That's let us build new features from scratch inside of the Next codebase while showing them seamlessly in the AngularJS UI, giving us a long-term migration path.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by cableshaft on Tuesday March 02, 2021 @11:44AM (#26317214)
I'll second that. We used AngularJS 1.x with TypeScript in an enterprise application.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by servercobra on Tuesday March 02, 2021 @08:58AM (#26315344)
I don't recall most major projects shipping with support for Coffeescript. Looking at my projects, the amount of "@types/*" I have are pretty small compared to a year or two ago because most projects ship types directly in their package now. Personally, I think it's here to stay.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by striking on Tuesday March 02, 2021 @12:52PM (#26318085)
I'd really like to hear what alternatives you have in mind for code in the JavaScript family that needs to have types. At my workplace, types are an important part of our workflow.

We've been using Flow as a type checker but are converting our code to TypeScript for the tooling, ecosystem, support, and hopefully improved performance.

TS has been running as a project for quite a while and a whole lot of folks have a stake in it. I think it's a pretty good bet.

Additionally, I was there when Angular 2 was announced, and the community had no idea what to do or when it was coming out and didn't know whether to dig their heels in and stay on 1 or what the migration path to 2 would look like. I think that's a slightly different story given the context.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by shakow on Tuesday March 02, 2021 @02:39PM (#26319520)
> Coffeescript in particular, are good historical references to what will happen to TS in a few years.

The thing is that many good ideas of Coffee ended up being integrated in newer versions of JS, so of course the need for it decreased; one could argue that Coffee's legacy lives in ES201x.

But there are no types in JS, and none planned.

Re:How an Anti-TypeScript “JavaScript developer” like me bec... by WorldMaker on Tuesday March 02, 2021 @03:24PM (#26320128)
Yeah, it would be great if TC39 made type hints syntactically valid but semantically ignored (ala Python's PEPs to that effect) so that type erasure was no longer needed as a "build step", but so far TC39 is still hugely aware of the controversies surrounding ES4 (the "lost" version of JS) and still very hesitant to do anything type related in JS.
Re:How an Anti-TypeScript “JavaScript developer” like me bec... by naavis on Tuesday March 02, 2021 @09:09AM (#26315446)
Looking at GitHub statistics, I would dare say TypeScript is pretty accepted: https://madnight.github.io/githut/#/pull_requests/2020/4

Out of all pull requests on GitHub in Q4/2020, 18.8% were JavaScript and 6.7% were TypeScript.

For reference CoffeeScript was at 0.25%. At its peak in 2014 it was at around 1.5%, when plain JavaScript was at over 20%.