dev-resources.site
for different kinds of informations.
Why does typescript not conditionally pick the right type in a union?
Published at
1/10/2020
Categories
typescript
help
question
Author
Thibault Maekelbergh
Why does the | (Union) operator not work as a logical or?
In the following snippets I would've expected it to see that the name
property is available in 1 of the provided union options? Instead it errors that it can't find name because it is not available in MyDevice
but it is available in the interface provided in the union.
How do you go about conditionally deciding to pick the interface instead of MyDevice when the name
property is available?
I know conditional types exist but that doesn't seem like an option because I'm providing plain interfaces and not types/interfaces with generics.
Articles
6 articles in total
Single point versioning with Fastlane for React Native
read article
"Fixing" React Navigation & iOS screen reader focus
read article
Why does typescript not conditionally pick the right type in a union?
currently reading
I'm writing a bash course
read article
🐳 Migrating InfluxDB databases to docker-compose
read article
Explain coroutines like I'm five
read article
Featured ones: