Live data from Hacker News

Using TypeScript with React

simonknott.de

111–120 of 195 posts

Re: Using TypeScript with React

#111
post #109

Earlier quoted context omitted.

This is a perfect example of a developer blaming themselves when in fact the real problem is that the tool is too complex with too many moving parts and that's why it breaks all the time. If you're a driver and your car keeps breaking down constantly, you wouldn't open up the hood each time, slap your forehead and say "It's OK, it's only the camshaft phase variator this time!" You rightly expect the car to just work.…

Not blaming myself, just grateful for getting this mess fixed. I cannot imagine working with tech like this on a daily basis, I'd probably ragequit in half a year

Ah yep. I know how it feels to solve some random useless problem that shouldn't even exist in the first place. It still feels great (like solving any other real problem). But it's a psychological trap that makes you feel more invested in the horrible technology which created the problem in the first place.

It's like filling out useless bureaucratic government forms. You still get a hit of satisfaction once you finish filling them out even though deep down you know it was a massive waste of time and the whole process could have been much simpler.

Re: Using TypeScript with React

#112

Earlier quoted context omitted.

That error you're seeing could be because you have multiple @types/react packages in your dependencies. You really should have just one version of each @types/* package installed. If you use yarn you can use `yarn why @types/react` to find out if you have multiple versions installed. To resolve these kids of errors, I usually uninstall all @types/* packages and then install them all at once again. Alternative is to u…

You can come up with any number of excuses but the bottom line is that TypeScript adds complexity which creates a lot of different problems which plain JavaScript does not have.

I mean, any time that you're not locking package versions, you're going to be in for a bad time, regardless of technology.

Re: Using TypeScript with React

#113
post #8

If you are going to learn a new programming language for web UI, why not go for Elm ? You get so much more than just static types with Elm.

Looked at Elm and it looks quite interesting. however concerns for going to it - Skill transfer. If I learn react, I can use my JavaScript skill to understand how everything works under the hood. If I learn Typescript with React, knowing react, I can focus on learning new language feature while not learning at the same time how to build the application. With Elm, I have to learn the language and the framework, all at…

I love Elm, but from a practical place, I think ReasonML is more fruitful to learn because of the fact that any valid ReasonML (sans JSX) is also valid ocaml, so you're nearly learning two languages at once.

https://reasonml.github.io/docs/en/what-and-why

I also feel the same way about F#, if you have any reason to care about C# or the .NET stack. It also can compile down to JS (and targets react)

Re: Using TypeScript with React

#114
post #85
post #77

Earlier quoted context omitted.

>If it's tedious, you're probably doing something wrong or sub-optimal. >IMHO we're reaching the point where typescript (or similar languages) should be used by default over untyped javascript in professional environments. It's like having tests, which are also not generally considered optional. Gotta love JS community. It flip-flops on some major aspect of system design roughly every year, yet people continue to arr…

The problem IMHO is the old adage of the devil being in the details. I see a lot of engineers talking about things like deriving types from enums, and meanwhile the type system will merrily let you do this: type Foo = {a: number} const o: Foo = JSON.parse('null') o.a = 1 It feels like people are lulling themselves into a false sense of security by making increasingly complex self-consistence schemes via type utilitie…

This is the equivalent of casting in Java. Is Java's type system unsound?

Re: Using TypeScript with React

#115
post #63
post #59

Typescript certainly eliminates a class of errors from a JS codebase and can also make development more productive. My issues with it are that it's just an extremely verbose language. Just like all Microsoft languages. All the while lacking advanced type system features like algebraic data types, pattern matching etc.

I feel almost the exact opposite: TypeScript is delightfully terse while still achieving its main goal of looking and feeling like JavaScript. I've used languages where things start looking like line noise (hi, Scala) and I very strongly do not get that feeling out of TypeScript. You have discriminated unions and the compiler is clever about them, so you can implement ADTs if you want them with a little but not a nas…

thanks for the mention of purify! This is going to be a game changer for me, I think. I can already see how this will benefit my TypeScript workflow!

Re: Using TypeScript with React

#116
post #96
post #85

Earlier quoted context omitted.

The problem IMHO is the old adage of the devil being in the details. I see a lot of engineers talking about things like deriving types from enums, and meanwhile the type system will merrily let you do this: type Foo = {a: number} const o: Foo = JSON.parse('null') o.a = 1 It feels like people are lulling themselves into a false sense of security by making increasingly complex self-consistence schemes via type utilitie…

As far as I don't like the "Angry Lisp Drunk Haskell" version of TS e.g. loads of ` ' mixed with functional concepts from half of the Haskell, which makes understanding code harder than necessary. Typescript is one of the rare good things in javascript. You have to understands JS, because there is always gun pointed at your foot, waiting to blow you away. Still TS makes this gun, a little bit harder to trigger. You c…

They have the unknown type since 3.0, which will force you to write runtime validation to satisfy the type checker.

It’s very helpful for dealing with untrusted/uncontrolled data.

Re: Using TypeScript with React

#117
post #77

Typescript is a lot easier to deal with if you stop treating it as optional and do it from day 1. Avoid using the any type and things fall in to place. If it's tedious, you're probably doing something wrong or sub-optimal. Or you're just dealing with a bit of hairy old javascript that probably needs a bit of refactoring in any case. IMHO we're reaching the point where typescript (or similar languages) should be used…

>If it's tedious, you're probably doing something wrong or sub-optimal. >IMHO we're reaching the point where typescript (or similar languages) should be used by default over untyped javascript in professional environments. It's like having tests, which are also not generally considered optional. Gotta love JS community. It flip-flops on some major aspect of system design roughly every year, yet people continue to arr…

I'm always confused when someone calls out a large group of people for not having a consistent opinion.

Gotta love Americans! They flip-flop on major aspects of policy making. One day they spout "ban guns!", the next they say "If need be I'll defend my right to bear arms with violence!"

Re: Using TypeScript with React

#118
post #86

Earlier quoted context omitted.

You were right, @types/react was resolved to both versions 15 and 16! God I'd totally buy you a beer. But why does this happen? The very first time for me a package manage installs two major versions for a package … Thanks A TON!

To me it usually happens if I upgrade one of the @types/* packages, and then yarn/npm decides to install a separate version of its dependencies, even if I already have a different (compatible) version. There is no easy way AFAICS to tell yarn/npm that you really only want a single version of each @types/* package. Same applies to most regular npm packages as well, for example you really only want a single version of…

Looks into the “resolutions” field for yarn. It does exactly this.

Re: Using TypeScript with React

#119

Earlier quoted context omitted.

>> javascript codebases become read only :-D This is BS. I've built very large JS projects with hundreds of thousands of lines and never had this problem. If your architecture is well designed and modular then refactorings are easy and localized to just a small number of files. On the other hand, TypeScript encourages spaghetti code which makes refactorings span more files; complex active instances end up getting pas…

Glad you enjoy large javascript projects and it works well for you. Architecture is important regardless of what language you are using.

Thanks. I feel like there should be a lot less discussion about tools and a lot more discussion about architecture. I find that with good architecture, the language doesn't really matter at all.

I've built high quality very complex projects in both JavaScript and TypeScript (both alone and as a team lead). My point is that I (and people of my skill level) can complete the project/subproject much faster with JavaScript so it gives me a lot more extra time to write tests.

Re: Using TypeScript with React

#120

Earlier quoted context omitted.

That error you're seeing could be because you have multiple @types/react packages in your dependencies. You really should have just one version of each @types/* package installed. If you use yarn you can use `yarn why @types/react` to find out if you have multiple versions installed. To resolve these kids of errors, I usually uninstall all @types/* packages and then install them all at once again. Alternative is to u…

You can come up with any number of excuses but the bottom line is that TypeScript adds complexity which creates a lot of different problems which plain JavaScript does not have.

It's not really excuses when the person doesn't understand what they are doing or why. The problem is entirely with how NPM downloads dependencies, not exactly typescript.

The OP is rightfully getting type errors due to conflicting type defs, why is that a bad thing?

Post reply on HN