Quantcast
Channel: Is there a way to prevent union types in TypeScript? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Is there a way to prevent union types in TypeScript?

$
0
0

I'm new to conditional types, so I tried the most obvious static way, no success:

type NoUnion<Key> =  Key extends 'a' ? 'a' :  Key extends 'b' ? 'b' :  never;type B = NoUnion<'a'|'b'>;

The B type is still a union. Would somebody please school me?

Here's a playground.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images