Protobuf to TypeScript Interface Generator

Convert Protocol Buffer .proto definitions to TypeScript interfaces and types with proper type mapping, nested messages, and enums.

Proto3

What is Protobuf to TypeScript Interface Generator?

Protocol Buffers (Protobuf) is Google's language-neutral serialization format used extensively in gRPC microservices, event-driven architectures, and cross-language data exchange. A .proto file defines messages, enums, and services, but frontend and Node.js applications need TypeScript types to work with that data safely. This tool parses your .proto definitions and generates TypeScript interfaces, type aliases, and enums that mirror the Protobuf schema. It handles the full range of Protobuf features — nested messages, enums, repeated fields, optional fields, map fields, and oneof unions — and maps every Protobuf scalar type to its correct TypeScript equivalent.

How to Use

  1. Paste your .proto file content into the input area — the parser supports syntax, message, enum, and service definitions.
  2. Configure options: choose whether fields use optional syntax (field?: Type) or explicit undefined (field: Type | undefined), whether to use the export keyword, and whether enums become TypeScript enums or string union types.
  3. Click 'Generate TypeScript' to parse the Protobuf schema and produce TypeScript interfaces and types.
  4. Review the generated code in the output panel and copy it into your frontend or Node.js project.

Why Use This Tool?

Generate type-safe TypeScript interfaces from Protobuf schemas without manual transcription
Automatic Protobuf scalar type to TypeScript type mapping — string, number, boolean, and Uint8Array are all correctly inferred
Full support for nested messages, enums, repeated fields, optional fields, map fields, and oneof discriminated unions
Choose between TypeScript enums and string union types for Protobuf enums depending on your project's style
Client-side conversion keeps your .proto files private — nothing is uploaded to any server

Tips & Best Practices

  • Use 'enum union types' for a more TypeScript-idiomatic approach — string unions like type Status = 'ACTIVE' | 'INACTIVE' work better with type narrowing than numeric enums.
  • Enable 'optional fields' for cleaner interfaces — field?: Type is more concise than field: Type | undefined and better reflects Protobuf's field presence semantics.
  • For oneof fields, the generator creates discriminated union types that enable type-safe narrowing with switch or if statements.
  • Map fields are converted to Record<Key, Value> which is the correct TypeScript representation of Protobuf's map type.
  • Nested messages become nested interfaces, keeping the generated code organized and matching your Protobuf schema structure.

Frequently Asked Questions

How are Protobuf scalar types mapped to TypeScript types?

string maps to string, int32/int64/sint32/sint64/fixed32/fixed64/sfixed32/sfixed64 all map to number, bool maps to boolean, float/double map to number, and bytes maps to Uint8Array. This matches the JSON encoding of Protobuf where all integer types become JavaScript numbers.

When should I NOT use this converter?

Avoid this tool when you need to generate gRPC service client code, server stubs, or serialization/deserialization logic — it only generates type definitions. Also, if your .proto file uses advanced features like custom options, extensions, or reserved statements that need to be preserved in the output, those are not currently supported.

How are Protobuf messages converted to TypeScript?

Each Protobuf message becomes a TypeScript interface. Fields within the message become properties of the interface. Repeated fields become arrays (Type[]), optional fields can be typed as Type | undefined or optional Type?: Type depending on your preference, and map fields become Record<Key, Value>.

How are Protobuf enums handled?

By default, Protobuf enums are converted to TypeScript enum declarations with numeric values. If you enable 'enum union types', each enum value becomes a string literal in a union type (e.g., type Status = 'ACTIVE' | 'INACTIVE'), which is more idiomatic in TypeScript and works better with type narrowing.

What about oneof fields?

Protobuf oneof fields are converted to TypeScript discriminated unions. Each variant becomes a separate property, and only one can be set at a time. This enables type-safe narrowing using the discriminant property in your application code.

Is my Protobuf data sent to a server?

No. All parsing and code generation runs entirely in your browser. Your .proto definitions never leave your device. No data is collected, stored, or transmitted to any server.

Real-world Examples

User Service Protobuf to TypeScript

Convert a user service Protobuf definition into TypeScript interfaces for a frontend application.

Input
syntax = "proto3";

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
  bool is_active = 4;
  repeated string roles = 5;
}

enum Role {
  ROLE_UNSPECIFIED = 0;
  ADMIN = 1;
  EDITOR = 2;
  VIEWER = 3;
}
Output
export enum Role {
  ROLE_UNSPECIFIED = 0,
  ADMIN = 1,
  EDITOR = 2,
  VIEWER = 3,
}

export interface User {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  roles: string[];
}

E-commerce Order with Nested Messages

Convert an e-commerce order Protobuf schema with nested messages and maps into TypeScript.

Input
syntax = "proto3";

message Order {
  string order_id = 1;
  map<string, int32> quantities = 2;
  OrderStatus status = 3;
  oneof delivery {
    string shipping_address = 4;
    string pickup_location = 5;
  }
}

enum OrderStatus {
  PENDING = 0;
  SHIPPED = 1;
  DELIVERED = 2;
}
Output
export enum OrderStatus {
  PENDING = 0,
  SHIPPED = 1,
  DELIVERED = 2,
}

export interface Order {
  orderId: string;
  quantities: Record<string, number>;
  status: OrderStatus;
  shippingAddress?: string;
  pickupLocation?: string;
}

Related Tools