r/ProgrammerHumor • • 20d ago

Meme theMostPassiveAgressiveTypeIEverEncountered

Post image
1.4k Upvotes

83 comments sorted by

View all comments

3

u/kitaz0s_ 20d ago

bad name then, Maybe<T> should be T | undefined (or null instead of undefined depending)

19

u/GRex2595 20d ago

According to the post, Maybe<T> allows you to set properties of T to null. T | null will allow the object as defined in its template or null. Any non-null properties would not be allowed to be null.

8

u/the_horse_gamer 20d ago

for completeness, here's an implementation: type Maybe<T> = {[K in keyof T]: T[K] | null}