DEV Community

Discussion on: TypeScript Tutorial - conditional types

Collapse
 
andrekovac profile image
André Kovac

Very nice series and article! I have two questions though:

  1. In the first example of StringOrArray we definitely need it. Changing never to any there would falsely allow wrong things to happen.

But if I replace never with any in Field (your second example) or FieldExtended (your last example) it would all still be type safe.

So is it a form of convention to use never as the last not handled condition to be on the safe side?

  1. I see that FieldExtended is basically the identity function with type checks. I can understand that a code editor might use such a function. But as an app developer, what would be a use-case for me to actually use something like FieldExtended?
Collapse
 
aexol profile image
Artur Czemiel
  1. Use never to notify developer that the type is not supported.