• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to discriminate an union against “never” type?

Resolved: How to discriminate an union against “never” type?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Let’s say I have this union:
The problem is how to discriminate the two possible types (in this case) using the radius field, for instance:
What I expect is a compiler error on the last calculation, because the radius field never exist on the TSquare type.
What’s wrong with this and how to solve this problem?

Answer:

Since TSquare does not need radius field you can declare it without it
Then you can modify function and check if radius is defined.

If you have better answer, please add a comment about this, thank you!

discriminated-union typescript typescript-never
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TypeScript does not recognize properties when instantiating interface array

27/03/2023

Resolved: How to make statement case insensitive when uploading a dta file with specified columns?

27/03/2023

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.