Typescript get type, that type guard function checks

I have a type guard function for type User. How do I extract the type, that this function "guards"? Using ReturnType<typeof isUser> obviously does not work since the return type of the function is boolean, not User. type User = { username: string } function isUser(value: unknown): value is User { return value !== null… Read More Typescript get type, that type guard function checks

How to type guard TypeScript type if instanceof only supports classes?

Need to type guard but instanceof doesn’t work with TypeScript types: type Letter = ‘A’ | ‘B’; const isLetter = (c: any): c is Letter => c instanceof Letter; // Error: ‘Letter’ only refers to a type, but is being used as a value here. // Expected usage: Filter via type guard. isLetter(‘a’); // Should… Read More How to type guard TypeScript type if instanceof only supports classes?