正在加载视频...

视频加载失败

❌ Avoid deeply nested validations that are hard to read. ✅ Instead use invariants.

206,841 次观看 • 1 年前 •via X (Twitter)

10 条评论

George Moller 的头像
George Moller1 年前

I've been working professionally with React and JavaScript for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

PATRYK 的头像
PATRYK1 年前

Don’t follow this advice. It makes your code less readable, it confuses other developers and your IDE. This level of abstraction is not helping anybody. Just use early return.

Vlad Tansky 的头像
Vlad Tansky1 年前

Nice, but wouldn’t it be easier to read code with if(!condition) throw new Error(“some message”) Instead of creating abstraction?

xavi 的头像
xavi1 年前

Just use fail fast/ early return and you’ll avoid that level of abstraction.

dcodes 🦀 的头像
dcodes 🦀1 年前

just use zod

Hamilton Greene 🐷🦔 的头像
Hamilton Greene 🐷🦔1 年前

I don't like this - you're hiding important control flow inside deeply nested functions. The caller must now know that implicitly your functions use exception control flow and throw on certain conditions (also hidden). Guards (if not x return) are usually better.

Remus 的头像
Remus1 年前

Dude an "any" wrapper function? That's scares the shit out of me

Proziam 的头像
Proziam1 年前

I have to know, what are you using for the animations and graphics? Looks clean

Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷 的头像
Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷1 年前

💯 This makes it super hard to read the code

Seve 的头像
Seve1 年前

"early bail" or "early return" is far better terminology

相关视频