r/programming • • Mar 29 '22

React 18 released!

https://reactjs.org/blog/2022/03/29/react-v18.html
749 Upvotes

183 comments sorted by

View all comments

144

u/Zaphoidx Mar 29 '22

Just waiting for the types to be updated and then it'll be usable!

107

u/bad_ts_is_just_js Mar 30 '22

It's insane to me that types still aren't a first class citizen in the React codebase. It feels wrong to be pulling in such a massive, complicated library and have to download the types for it from a third party

16

u/Zaphoidx Mar 30 '22

To be honest, I'd completely forgotten that this was the case when trying to quickly upgrade one of our projects.

The React team definitely needs to take over the ownership of typing in the project, so we can get both on the release of a major version.

→ More replies (1)

37

u/_eps1lon Mar 29 '22

For react-dom you can already import from react-dom/client. For react just to import type {} from 'react/next' once and you have the latest typings available.

The rest is underway in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210

10

u/Zaphoidx Mar 29 '22

Yeah I've been following your PR!

It looks like the types for createRoot don't seem to support the return types for getElementById, so not sure if there needs to be more type updates in react-dom to be done before it becomes fully usable?

→ More replies (1)

0

u/[deleted] Mar 29 '22

[deleted]

89

u/budasaurus Mar 29 '22

Literally just moved to a new team that is using JS and not TS and I hate my life. So many little issues could have been caught ahead of time.

58

u/Sprite87 Mar 29 '22

could be worse, I work in a company where core (most senior) engineers refuse to write tests.

13

u/Vakz Mar 30 '22

I know it's such a trope for developers to say they would leave because of some issue, but honestly, senior developers refusing to write tests is one of those things that would instantly make me look for a new job. Nothing is worth the frustration it causes.

15

u/JohhnyTheKid Mar 30 '22

One of the senior engineers at my company told me the other day that he won't be writing typescript (which the majority of our code base is in) because "he never understood the need for it". He also hasn't written a single test ever. His code is incredibly frustrating to work with to the point where often times something written by him doesn't work at all, yet he still commits that shit straight to development branch which results in other people having to fix his shit. I have an interview with another company today. This is a perfect example why someone should never be made a senior engineer over years worked alone.

14

u/Zaphoidx Mar 30 '22

That also sounds like a complete breakdown of standard processes within the dev team/company. No one should be able to commit straight to a branch that is used by several other people. That is just asking for a whole world of avoidable problems.

10

u/Vakz Mar 30 '22

Pull/merge requests would be another thing I consider a bare minimum for any non-solo projects. Even a minimal code review that at least makes someone click "accept" and a pipeline that at least builds the project should be a requirement at any company.

7

u/JohhnyTheKid Mar 30 '22

Exactly. This guy is more "senior" than everyone else on my team. He has never used modern workflows and thus thinks they're useless and just vetoes everything or just goes right ahead and does his own stupid shit despite what other's are doing. I've tried enforcing protected branches, mandatory code reviews, proper commit message etiquette and all other basic shit but this man just ignores all of it and refuses to listen to reason. Before I came to this team it was him and some other guy who quit shortly after and they were both literally just commiting everything to master. It's counter productive man child behavior, but management trusts him and his decisions more because he's been with the company for much longer. All of this is the reason why I'm quitting. No matter how I try explaining stuff and why it's necessary he simply just calls it cargo culting and pulls rank on me.

6

u/Vakz Mar 30 '22

Good luck with your interview. Remember to name him as a specific reason why you're quitting, or if you're not willing to name and shame then at least say you've found it impossible to work with people who don't care about quality results. Mention how much paid work time you've spent fixing his mistakes. If they care at all either about this bad quality of the code, or at the very least about the wasted time which translates into wasted money, they should realize they need to do something. If they still don't then, well, fuck 'em, they deserve it.

→ More replies (1)

21

u/budasaurus Mar 29 '22

I… I don’t even know what to say other than I am so sorry.

6

u/zephyrtr Mar 30 '22

Just 10x programmer things.

→ More replies (3)

16

u/Accomplished_End_138 Mar 30 '22

My condolances.

We have seniors who are still getting used to typescript (though.. i say this as the staff teaching it)

I just wish they would stop forcing the use of connect for redux... and redux.. so overly complicated for this app.

→ More replies (2)
→ More replies (5)

13

u/International_Cell_3 Mar 30 '22

But types slow you down! The compiler is in your way! Why fail at compile time when you can just write a unit test! And other arguments made by dynamic typing advocates that miss the point!

/s, hopefully obvious

→ More replies (3)

9

u/[deleted] Mar 30 '22

How about just use typescript jsdoc annotations and an editor that supports them? It makes a not insignificant difference if your tooling supports it (vscode does) and it’s unobtrusive because it’s just comments.

20

u/NoInkling Mar 30 '22

it’s unobtrusive because it’s just comments

Not in my experience. Just look at the syntax for type casting/assertions. Also, you can't import a namespace (unless it also happens to be a value), so if you want to reference multiple types from the same package you have to import('some-package').SomeType multiple times. Other missing features can lead you down the path of other messy workarounds.

As someone speaking from experience, if you try and make full use of jsdoc for type checking/linting you're basically writing a messy, bastardized, feature-lacking version of TS. If jsdoc is your only option it's better than nothing, but I'd recommend sticking with relatively basic annotations in key places, rather than aiming for comprehensiveness.

→ More replies (2)

7

u/Accomplished_End_138 Mar 30 '22

I find typescript much easier to write. But jsdoc annotations are at least passable

→ More replies (1)
→ More replies (1)

47

u/Zaphoidx Mar 29 '22

There definitely still is a time and a place for plain JavaScript, but it's back with its origins now as a scripting language.

If you want to build a fully-fledged application that's robust, then it just makes much more sense to build it in TypeScript.

13

u/L3tum Mar 29 '22

Whenever I start a new JavaScript project I code for a bit and then I get to a function and think "I really want to tell it to be a specific type" and end up setting up the TS stack as well.

The only time I don't do this is if I literally only code a button handler for a website.

9

u/r0ck0 Mar 30 '22 edited Mar 31 '22

Yeah for me, it's TypeScript for everything... aside from like throwing 50 lines of JS into a wordpress site or something.

Another way to look at it is... am I working on more than one JS file in the whole project? If so, it warrants TS.

→ More replies (5)
→ More replies (7)