Improve GenerateForgotPasswordEmailHTML (and similar) TS types
#10441
HappyEmu
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When you add
authto a collection, you can configure for example thegenerateEmailHTMLhook. The types for these kind of functions are really not helpful:For example, when I have a
nursescollection, I cannot assert the type ofusercorrectly, becauseargsis allowed to beundefined. So code like this:Will infer type
anyfor thenursebinding. The most obvious thing to do would be to add the type to theuserparameter:But that does not work since the whole
argsand indeed{ user }can beundefinedas by the types mentioned above. So I'd have to writeto make the consumer code compatible with the types. But now
nurseis inferred toanyagain, since the wholeargscan beundefined. Apparently in TS,const { foo } = undefinedcausesfooto be inferred asany, and notnevereven though that line throws an error.So in order to write correct TS code, where
nursehas the appropriate type, I'd have to writewhich I hope everybody agrees is nothing anybody should need to write given the assumption that indeed
argsor any of its parts{req, user, token}can ever be nullish, given thatgenerateEmailHTMLis called like this:where neither
req, token, nor usercan be nullish. Even if they could benullorundefined, what would be the fallback return value if any of these are missing?In conclusion: Why are these function parameters nullable?
Beta Was this translation helpful? Give feedback.
All reactions