How do you handle incompatible null/undefined from discord.js typings?
Note: This is not a typescript problem, I know how to solve it from different ways. I'm just looking for feedbacks or djs-specific answers/workarounds
There are a lot of places where
discord.js
uses a mix of null/undefined and sometimes it gets really frustrating. For example this is a very common occurence in my codebase :
This leads to a type mismatch which triggers typescript.
Is it expected that types within a single library don't match like this?
How do you handle this in your discord.js codebase? I'm tired of adding ?? undefined
(which makes no sense) or a TS null assertion !
…
Thank you!
(PS: you should update the djs versions in the tags)7 Replies
.avatarURL() ?? undefined
it's the only way:/
Do you think it's worth oppening a GH issue? At least to have optional object properties accept
null
s (iconURL?: string | null
, etc)I highly doubt DJS would accept a PR like that tbh but maybe @vladdy will contradict me
Yes
Probably would, can't guarantee
Sounds like discord issues, just try again
Wish i could help but idk why that's happening
Update your app
See if that solves it
i'll make the issue and let you debate over there
GitHub
Homogenise null and undefined typings within djs APIs · Issue #9829...
Which application or package is this feature request for? discord.js Feature Often when using discord.js APIs together, types are incompatible because of undefined/null discrepancies. This is very ...
probably should have made a discussion now that i think of it
oh well