'Typescript - Defining a Hybrid Type Which Accepts Both Generics Form And Non-generics Form

I wondered if there's a good way to achieve something like this:

type Animal = Dog | Cat

// This one is expected to narrow the type in case I have some extra information
type Animal<T> = T extends X ? Dog : Cat

In other words, I want to declare 2 types, one with generics and one without, while the generic one is expected to be a subset (which is also more specific) of the non-generic type. I know I can achieve it with 2 different type declerations, but this option wont guarantee that the generic type will be a subset of the other type. Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source