r/ProgrammerHumor • • Sep 17 '26

Meme theMostPassiveAgressiveTypeIEverEncountered

Post image
1.4k Upvotes

83 comments sorted by

View all comments

Show parent comment

18

u/GRex2595 Sep 17 '26

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.

7

u/the_horse_gamer Sep 17 '26

for completeness, here's an implementation:

type Maybe<T> = {[K in keyof T]: T[K] | null}

3

u/Reashu Sep 17 '26

Right, that's why it's a bad name.

4

u/GRex2595 Sep 17 '26

Sometimes we deal with Maybe<T>s because AnyPropertyCanBeSetToNull<T> is bad for different reasons. I don't judge too hard when I see something that doesn't have a good name and went with more or less the least bad one they could come up with.

1

u/jordanbtucker Sep 18 '26

Maybe is a bad name because there is precedent to what that type should mean. NullableProps is better and it's not as egregious as your example.

1

u/GRex2595 Sep 18 '26

Great. You should go find whatever code base is using this name and submit a PR.

1

u/danielcw189 Sep 19 '26

because AnyPropertyCanBeSetToNull<T> is bad for different reasons.

such as?

1

u/GRex2595 Sep 19 '26

Mostly it's just a massive pain. It takes up a bunch of space and makes it harder to read the code as a result. If you can avoid long names, that's generally better. I couldn't imagine an AnyPropertyCanBeSetToNull<Partial<ConfigurationLoader>> testDefaultUserConfigurationLoader in my codebase, and I'll probably ask somebody who submits that in a PR to come up with anything else.