from Hacker News

To Type or Not to Type?

by beginnings on 4/26/23, 4:12 PM with 5 comments

I'm currently quite early stage on the frontend work for my project, at a point where it wouldn't be too much hassle to convert to typescript although it would be some.

My backend is c++ and I use some Rust for tools where they have a better library than c++ (rare), so i'm not averse to strongly typed languages, but those languages were built with types from the ground up.

I see a lot of debate on this topic and a common reason given for using typescript is it helps working in a large team, I am working solo so this isn't a benefit for me.

It seems like the whole web scene is moving towards typescript but my gut is screaming no, there's just something off about it to me, it feels like a never ending afterthought, strapping on types to eternity.

Is it unnecessary overhead for minimal returns, or am I missing something?

  • by aastronaut on 4/26/23, 5:32 PM

    > my gut is screaming no

    seems like you already made up your mind, so why bother?

    TypeScript is helpful (or at least meant to be) for teams as it aims to block the cleverness of its individual contributors. Especially people only familiar with dynamic type systems are rather fighting a static type checker at first and "it's not helping them". A "strong" type checker should enforce everyone to write stuff in a simpler form and that gets in the way of productivity for some people.

    If you can maintain your mindset and write your code in a simple form that could easily satisfy a type checker (coming from rust), then why bother with additional tooling if it won't provide more value to you? Or to phrase it differently: if you can maintain a strong mindset with confidence, bringing in additional tooling for that project later on, when it will be become plausible, won't be that hard. But if you doubt your mindset, it might be a helpful choice to let a type checker look over your shoulder from the beginning.

  • by obpe on 4/26/23, 7:18 PM

    I recently started working on a project that added TS after the project was very mature. The biggest problem is the project was never intended to have types so they feel very shoehorned in and, imo, cause far more problems than they are solving. I think in this specific case the project simply should not have been updated with types.

    I have worked with JS a lot and have only used TS in this one instance. I would be interested in working on a project that included TS from the beginning to see a better representation of TS.

    Also, fwiw, we have solved many of the same problems with linting and automated tests. But this requires education and maintenance; it would be interesting to compare this effort with a TS project.

  • by schwartzworld on 4/27/23, 1:52 AM

    > strapping on types to eternity.

    You can write TS that way. Most people who write a lot of typescript don't though. Instead of describing JavaScript's inherent limitlessness, you can deliberately reduce the size of the infinity within any given context.

    Your app just knows what values it's going to get out of a function. Your IDE happily suggests the exact right set of property names to make a function work right.

    You're not really working alone because you're going to be integrating with external libraries and APIs. Many of them include typescript support because it takes the guesswork out of working with them.

  • by AnimalMuppet on 4/26/23, 4:22 PM

    Types are useful, even as a solo developer. My memory just isn't good enough. It's nice to have a compiler tell me: "Yeah, there on line 974? You're doing something stupid there; go fix it."

    Note that I said types are useful. I have no experience with TypeScript.