DEV Community

Discussion on: 150+ Typescript one-liners [code snippets].

Collapse
 
moopet profile image
Ben Sinclair

A lot of these are pretty dangerous.

Not because they're wrong, necessarily, but more because they're "one-liners" in the same way that people's "pure CSS" drawings are done in pure CSS.

When you get to the point of having a "one-liner" that's 348 characters long, you have to consider getting a wider monitor. Like, a 65" wide monitor. Otherwise, you're going to wrap. And you know where you're going to wrap? At the points where you would reasonably be expected to have had a line break.

You can take any application and minimise it to one line if you want, you can make the variable names terse and impenetrable, you can exclude guard clauses and make assumptions about things other than just types, but it doesn't make good code.

There's nothing wrong with these ideas, but why force them onto one long, long, unreadably-long line for the sake of a catchy post title?

"Short, re-usable Typescript snippets" would describe them just as well then.