When I use the following code snippet:
type Identity <T extends string> = T;
type MaybeString = string | undefined;
type StringOrNever = MaybeString extends undefined ? never : Identity<MaybeString>;
The compiler raises an error stating that 'undefined' is not assignable to type 'string' when using MaybeString as the Identity parameter.
I started wondering if this issue could be related to the distributive property of conditional types, so I decided to try the following:
type StringOrNever = [MaybeString] extends [undefined] ? [never] : Identity<MaybeString>;
Unfortunately, this approach did not resolve the error either.
I'm confused about what I might be doing wrong here. Can anyone provide some insights?