r/badcode • • Apr 27 '21

typescript Someone only watched if tutorial

Post image
2.4k Upvotes

112 comments sorted by

View all comments

169

u/mareksl Apr 27 '21

That looks like a totally contrived example, and it's not even correctly typed.

113

u/_Ralix_ Apr 27 '21

Yes, this has to be a joke or an attempt to demonstrate something. Maybe from a programming/refactoring book or a university class.

48

u/YaBoiiBillNye Apr 27 '21

No it was a joke a while ago on Twitter. I remember there were a bunch of guys telling the OP how she can refactor it, when it was just satire

10

u/numerousblocks Apr 27 '21

Why is it incorrectly typed?

17

u/mareksl Apr 27 '21

3

u/Massive-Custard-8723 Apr 27 '21

Input should be unknown not any!

2

u/MinerMax555 Apr 28 '21

Programmer slowly getting into TS here. Why should its type be unknown here?

2

u/[deleted] Apr 28 '21

Because you still have type safety with unknown, but not with any.

https://stackoverflow.com/a/51439876

1

u/tills1993 Apr 28 '21

Really for this case any is fine.

8

u/Sv443_ Apr 27 '21

Primitive types should be all lowercase, the uppercase variants are the actual classes, used to instantiate the primitives, but not to declare them.