Skip to content

Typedefs

Typedefs create named aliases for existing types, improving readability without adding wire overhead.

Syntax

typedef UserId = u4;
typedef Email = string;
typedef Timestamp = datetime;

A typedef is a compile-time alias. On the wire, it is identical to the underlying type — there is no additional wrapping or indirection.

Usage

Use typedefs in messages, services, and other type positions:

typedef UserId = u4;
typedef SpaceId = u4;

msg Membership {
    userId: UserId;
    spaceId: SpaceId;
    joinedAt: datetime;
}

service MemberService(space: SpaceId) {
    GetMember(user: UserId): Membership;
}

Generated Code

In C#, typedefs generate global type aliases in moduleInit.cs:

global using UserId = uint;
global using SpaceId = uint;

In TypeScript, they generate type aliases:

export type UserId = number;
export type SpaceId = number;