I'm trying to create a higher order function that allows me to create a function which confirms a type via a type guard.
type Shape = Circle | Triangle | Rectangle
enum Type { Circle, Triangle, Rectangle }
interface Circle {
type: Type.Circle;
diameter: number;
}
interface Triangle {
type: Type.Triangle;
width: number;
}
interface Rectangle {
type: Type.Rectangle;
width: number;
height: number;
}
const isShape = (condition: Type) => (shape: Shape): shape is ? => shape.type == condition;
const isCircle = isShape(Type.Circle);
In the above example, I want the isCircle
function to return whether the type is Circle
. The ?
is a placeholder since I can't get it to work.