Suppose I have a constrained type function type Foo<T extends string> that only accepts types that extend string. I would expect the following code to compile. Instead, it gives a type error.
type Foo<T extends string> = T;
type UseFoo1<T> = NonNullable<T> extends string
? (param: Foo<NonNullable<T>>) => void
^^^^^^^^^^^^^^
: () => void;
Type 'NonNullable<T>' does not satisfy the constraint 'string'.
Type 'T' is not assignable to type 'string'.
Why can't TypeScript derive that NonNullable<T> extends string?
In the following cases, it does work.
type UseFoo2<T> = T extends string
? (param: Foo<T>) => void
: () => void;
type UseFoo3<T> = NonNullable<T> extends string
? Foo<NonNullable<T>>
: never;