Skip to content

How to solve Object is possibly 'undefined' errors without optional chaining #137

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

Closed
tom-richter opened this issue Apr 13, 2021 · 2 comments
Labels
question Further information is requested

Comments

@tom-richter
Copy link

Since optional chaining and nullish coalescing not being supported in vue 2 templates I wonder what to do with possibly undefined values like this {{ tags.get(question.tagId).name }} which gives me the error Object is possibly 'undefined'. Is there a possibility to solve this in the template or do have to use a getter in the script part of the component?

@tom-richter tom-richter changed the title How to solve Object is possibly 'undefined' errors without optinal chaining How to solve Object is possibly 'undefined' errors without optional chaining Apr 13, 2021
@johnsoncodehk
Copy link
Member

Actually I'm not sure, you could try to ask in official typescript channel: https://discord.com/channels/325477692906536972/331999220125138944

@johnsoncodehk johnsoncodehk added the question Further information is requested label Apr 13, 2021
@johnsoncodehk
Copy link
Member

@tom-richter maybe you can do this {{ (tags.get(question.tagId) || {}).name }}.

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

No branches or pull requests

2 participants