Directions fit perfectly as a union of string literals. A switch on the direction narrows the union and makes it obvious how to adjust coordinates. Returning a new object keeps code predictable and avoids side effects.
type Step = "up" | "down" | "left" | "right";Move by exactly one unit each time and keep the function pure.
type Direction = 'up' | 'down' | 'left' | 'right'.type Point = { x: number; y: number }.move(p: Point, dir: Direction): Point returning a new point moved by 1 in the given direction.