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

vue-tsc wrongly infers "undefined" with optional chaining #1618

Closed
TheDutchCoder opened this issue Jul 21, 2022 · 1 comment
Closed

vue-tsc wrongly infers "undefined" with optional chaining #1618

TheDutchCoder opened this issue Jul 21, 2022 · 1 comment

Comments

@TheDutchCoder
Copy link

Consider the following code and types:

const selectedCollection: Ref<Col1 | Col2 | null> = ref(null)
const selectedCollectionId = computed(() => selectedCollection.value?.id)
const selectedCollectionAccountId = computed(() => selectedCollection.value?.collaborators.find(col => col.id === '1'))  // throws "This expression is not callable."

For some reason, vue-tsc is not able to remove the undefined type when using the optional chaining. It still thinks that selectedColelction.value can be null, even though the optional chaining should take care of that.

As a reference, here's the same implementation in regular TypeScript: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgMIHsA2cBGBnARmQG8AoZZAfUrAE8AHCEOAWwgC5kAiDTbHdFDhhBXANzlkwACac8YKKADmEgL6lSoSLEQpeuPACYSk6nUbM2nHln6DhoiRRlyFytRq3R4SNFiJkFGYMTKwc3LyYEAhgwOgg4pIuyPKKICqSiAjoAK7gAJKyKW7pyAA+yCA5fE7I2eBCMYWuaUrlldWYtdl8uPYiUHic+vgEANoAuh6kEAAe9IJgUuDeun6YxoFUNCGW4TZ80bHxic5Fqe6ZCNl5YM3Fre1VNZL1Coh35yVtFc9dr7Y+kIBkN1gZDJNpvV5Mg4MN-MgALwmChBHYWMLWSJHOIJAA0kjOnAA5ARiQTUXVAQJgYJQZMKaisrkCkU-oyKG9Gp9OH9SOpSNCljh4RskSjUcEMVYIrYcScOVIiqTyYSqb0aQ5BpwGWrmbd7uy1VyPobOvyNELkDBxQAKHqiogVXjGX6dACUSIAfBLOfE8FgIAA6TDoJT2rAAfiDPTstMGQZgoGkEcw3vVQZkSMRyJV7vd-KAA

@TheDutchCoder
Copy link
Author

This looks like a limitation in TS: microsoft/TypeScript#33591

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

No branches or pull requests

1 participant