til

How to check if the inferred type is `any`

typescript

You can check if a type is any using this utility:

type IsAny<T> = 0 extends (1 & T) ? true : false;

Some checks:

// Returns true
type R = IsAny<any>;
type J = IsAny<ReturnType<typeof JSON.parse>>;

// Returns fale
type A = IsAny<"A">;
type B = IsAny<{}>;
type C = IsAny<unknown>;

Check this TypeScript playground

I learnt this from @WrocTypeScript