Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use optional chaining in the type guard for greater safety #344

Merged

Conversation

suddjian
Copy link
Contributor

@suddjian suddjian commented May 14, 2024

The generated is{entryName} functions are only useful if you're confident that the thing you're passing in is, at least, a fully-fleshed-out Entry type. But it's possible to not know what exactly you have. In my case, I have a situation where my object is either a string, an unresolved link, or one of three entry types. And in that case the caller of is{entryName} will need to do additional checks to make sure it's even safe to call this function, or risk throwing an exception. Better to have the function just behave safely and do its job all the way.

As a general practice in TS, isXYZ functions should be safe to call with any argument.

@marcolink
Copy link
Collaborator

Hi @suddjian 👋
Thanks for your contribution 🙏 . Can you please add a description to the PR and some reasoning behind the requested change? Would love to see the use cases.

@suddjian
Copy link
Contributor Author

I added some more information. Please do let me know if there's any other clarification I can provide.

@suddjian
Copy link
Contributor Author

Any chance of merging this?

@marcolink marcolink merged commit a92c62f into contentful-userland:master May 31, 2024
@marcolink
Copy link
Collaborator

#346

@marcolink
Copy link
Collaborator

@suddjian version 2.15.2 comes with your changes - have a nice weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants