sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.42k stars 548 forks source link

IsAny not working with "any" as generic type argument under different constraint #947

Open Xriuk opened 3 months ago

Xriuk commented 3 months ago

Reproduction

type Generic<Type extends string> = Type;
type GenericInstance = Generic<any>;

type T1 = GenericInstance extends Generic<infer T> ? T : never; // any
type T2 = IsAny<T1>; // true, as it should be

type T3 = GenericInstance extends Generic<infer T> ? IsAny<T> : never; // false, but should be true

// I guess the second inference removes references to the type being a string?
type T4 = GenericInstance extends Generic<infer T> ? IsAny<T extends (infer TT) ? TT : never> : never; // true, as it should be

My wild guess is that it has something to do with the generic constraint <Type extends string> and the returned any is still seen as some sort of string in this case, might be a TS bug?

Upvote & Fund

Fund with Polar