@runtyped/type
v1.0.20-alpha.5
Published
@runtyped/type, the fastest universal TypeScript serializer and validator with JIT engine for frontend, backend, http-transport, RPC, and database, with built-in validations, for Browser/NodeJS.
Maintainers
Readme
@runtyped/type
TypeScript types disappear at runtime. Runtyped changes that, preserving types at runtime via a compiler plugin.
import { is, cast, validate, serialize, typeOf, toJsonSchema } from '@runtyped/type';
interface User {
id: number;
registered: Date;
username: string;
}
// Deserialize JSON to typed objects (strings become Dates, etc.)
const user = cast<User>({
id: 1,
registered: '2024-01-15T10:30:00Z',
username: 'peter'
});
user.registered instanceof Date; // true
// Validate data against type
validate<User>({ id: 'not a number' });
// [{ path: 'id', message: 'Not a number' }]
// Serialize to JSON-safe output
serialize<User>(user);
// { id: 1, registered: '2024-01-15T10:30:00.000Z', username: 'peter' }
// Full runtime type reflection
const type = typeOf<User>();
// Convert type to JSON Schema
const schema = toJsonSchema<User>();Use with @runtyped/type-compiler. Check the documentation at https://github.com/runtyped/runtyped.
