Skip to main content
The @zon-lib/zon package comes with bundled TypeScript definitions (.d.ts). You don’t need to install @types/ packages separately.

Configuration

Ensure your tsconfig.json can resolve the types:
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "esnext"
  }
}

Type-Safe Usage

You can import the types explicitly to use in your function signatures.
api.ts
import { ZonReader } from '@zon-lib/zon';

// 1. Type annotations for your reader function
export function parseUser(reader: ZonReader): string {
    const root = reader.rootOffset;
    return reader.readString(root);
}

// 2. Handling Serialization
import { serialize } from '@zon-lib/zon';

interface User {
    name: string;
    score: number;
}

const user: User = { name: "Alice", score: 99 };
const binary: Uint8Array = serialize(user);
IntelliSense: Your IDE (VS Code) will autocomplete methods like reader.readU32(offset) and prompt you if you pass incorrect parameters.