TypeScript Contracts: Interfaces Need Runtime Boundaries
TypeScript makes application contracts easier to express and refactor, but runtime validation and a narrow Gateway adapter still decide whether external input is safe to use.
Why LNSAT uses TypeScript at the application edge
TypeScript gives application code named types, interfaces, unions, and narrowing rules. The Handbook shows how a union can be narrowed with ordinary JavaScript checks such as typeof or Array.isArray. This makes packet shapes, API responses, and adapter results easier to review and keeps changes visible across a client or Gateway surface.
The tradeoff is that TypeScript is erased before JavaScript runs. Types help during development and compilation, but they do not inspect untrusted JSON, a browser request, an environment variable, or a response from another service at runtime. A contract therefore needs both static types and explicit runtime validation at its boundary.
Adapters and Gateway have different jobs
A TypeScript adapter translates an application request into a chosen API, CLI, MCP transport, or enterprise system format. It should validate inputs, preserve request identity, normalize provider errors, and report whether an effect is pending, completed, failed, or unknown. TypeScript interfaces document those states for callers; runtime checks enforce what actually arrived.
The Gateway owns authority. An adapter can carry a request to the boundary, but it cannot turn tool availability, a valid TypeScript object, or a model recommendation into approval. LNSAT's public source describes the Gateway as the security boundary and keeps application presentation and external-system adapters separate from policy enforcement and durable evidence.
JavaScript and Node.js remain part of the threat model
Node.js runs JavaScript outside a browser and provides runtime APIs for networking, files, processes, and other system work. That makes it useful for LNSAT API and integration surfaces, while also making input handling, dependency behavior, event-loop pressure, secrets, and process permissions part of the security review.
Static contract checks do not prove authentication, authorization, replay resistance, or complete error recovery. Pair TypeScript types with runtime validation, narrow adapters, explicit idempotency and receipt fields, and tests for malformed and repeated requests. Related guidance: API and Event Contracts, MCP Integrations Need Contracts, and Human Approval Is a System Boundary.