Skip to content

prefer-millisecond-control-duration-schema

Require application-owned Zod control-duration fields to use millisecond granularity.

Why

Second-granularity timeout and scheduling controls lose precision and invite implicit unit conversion at API boundaries. Encoding milliseconds in the schema keeps the unit explicit and composes with platform timing APIs.

Fix

Rename the field with an Ms/_ms suffix and express its bounds and default in milliseconds; update the owning API contract rather than converting in application code.

Examples

Before — flagged Do not expose second-granularity timeout controls
src/request.ts
import { z } from "zod";
export const RequestSchema = z.object({
timeout_seconds: z.number().int().min(1).max(300).default(30),
});
After — preferred Encode control timing in milliseconds
src/request.ts
import { z } from "zod";
export const RequestSchema = z.object({
timeoutMs: z.number().int().min(1000).max(300000).default(30000),
});