Live data from Hacker News

I Was Wrong About TypeScript

triplet.fi

91–100 of 194 posts

Re: I Was Wrong About TypeScript

#91
It seems like people are trying to use types as a substitute for tests and a way to protect themselves from unintended mutations.

But if you write tests already and use immutable data structures, what benefits does TS bring to people whose background isn't in strongly typed languages?

Re: I Was Wrong About TypeScript

#92
post #91

It seems like people are trying to use types as a substitute for tests and a way to protect themselves from unintended mutations. But if you write tests already and use immutable data structures, what benefits does TS bring to people whose background isn't in strongly typed languages?

Tests are weak evidence of the validity of a piece of data at runtime. Types are proof. The stronger your type system, the more you can prove.

Re: I Was Wrong About TypeScript

#93
Does anyone have a good tutorial on migrating existing JS codebases to TS?

Talking specifically Angular 1 if you have one, otherwise a general tutorial is fine.

I'm interested in whether it is worth the effort migrating a pretty large frontend codebase.

Re: I Was Wrong About TypeScript

#94
post #32

The thing with 3rd party libs is, often there are no type defs, especially bleeding edge stuff :/ Also VSC often is flunky with picking up defs... sometimes you open a file and some are missing. Or imports with numbers don't work. On the other hand, using big libs like babylonjs is charming with all the auto complete :)

Not even Microsoft's own JavaScript libraries (e.g. Excel) have first-party type defs, at least as of a few months ago. Making matters worse, that aforementioned Excel library has polymorphic parameters everywhere. We gave it a shot with ng2 on a one-off, but honestly TypeScript just slowed us down and the juniors tried sneaking "Any spam" through code reviews.

Re: I Was Wrong About TypeScript

#95
post #46

I see a lot of Angular comments, has anyone had good/bad experiences with TypeScript and React?

From a React newbies's perspective, the React community is much more in the es6 camp than Typescript. Many of the starter kits are in es6. It's not a huge deal. I actually write most of my front-end code these days in Aurelia, which is written in es6, but they actually have type annotations which Babel knows how to deal with. So basically the tooling can auto-generate the *.d.ts files for you. That said, Typescript n…

Shameless plug: When we've started switching to TypeScript and was looking for a good starter, we've couldn't find any that we've liked so we've created & open sourced our own. Maybe it can help people who are considering using TypeScript with React: https://github.com/barbar/vortigern

Re: I Was Wrong About TypeScript

#96
post #92
post #91

It seems like people are trying to use types as a substitute for tests and a way to protect themselves from unintended mutations. But if you write tests already and use immutable data structures, what benefits does TS bring to people whose background isn't in strongly typed languages?

Tests are weak evidence of the validity of a piece of data at runtime. Types are proof. The stronger your type system, the more you can prove.

But doesn't Typescript compile to JS, thus there's actually no type-checking at runtime?

Certainly type checking can prove that it's the right type, but in my experience knowing that it's the right type but the wrong data is useless, I care if it's the exact data it's supposed to be.

How does type checking protect you (or someone else) from inadvertently mutating a value without changing it type and causing problems later? It's perfectly possible to do this without having any checks for class/instance throw a warning, unless there's something I'm missing.

Re: I Was Wrong About TypeScript

#97

Earlier quoted context omitted.

I was just about to complain how TS fails totally for typechecking backbone models or immutablejs datastructures: both situations where obj.get("foo") and obj.get("bar") return a particular type but there's no way of having TS handle that except defining them as any. But it turns out string literal types in 1.8 will make that work. And this was out since February! I should reevaluate TS for my omniscient project.

IIRC there is no ergonomic way to define typed records for Immutable.js ?

If I recall correctly, you still can't type Immutable.js nicely with Flow, let alone Typescript, so I'm not surprised tbh

Re: I Was Wrong About TypeScript

#98
post #91

It seems like people are trying to use types as a substitute for tests and a way to protect themselves from unintended mutations. But if you write tests already and use immutable data structures, what benefits does TS bring to people whose background isn't in strongly typed languages?

[deleted]

Re: I Was Wrong About TypeScript

#99
post #91

It seems like people are trying to use types as a substitute for tests and a way to protect themselves from unintended mutations. But if you write tests already and use immutable data structures, what benefits does TS bring to people whose background isn't in strongly typed languages?

It's not just javascript with types. The language is written in a way that makes it much easier for machines to understand your code. I'm not talking about just tests and linting.

Check out some typescript tooling videos, this one was shown at an angular 2 conference but you don't need to know any angular to watch it:

https://www.youtube.com/watch?v=e3djIqAGqZo

Re: I Was Wrong About TypeScript

#100
post #35

I just wish TS was based on CoffeeScript.

Coffeescript was such a pain though, if something you wanted to edit was written in coffeescript, you'd have to learn coffeescript to touch it.

If something is written in typescript it doesn't matter if you don't know it. Just write what you want to change in javascript. All javascript is typescript.

Post reply on HN