Tea
DocsPlaygroundExamplesReferenceCommunity
GitHub

Tea Language

A strongly typed scripting language for native tools.

© 2026 Tea Language.

ContributingCommunityRepository

Get Started

InstallationGetting StartedCLI

Language

SyntaxTypesFunctionsStructsGenericsPattern MatchingError HandlingModulesTesting

Project

Code StyleContributing

Language

Structs

Use structs to define domain-specific record types with named fields and strong typing.

Structs let you group related fields into one named type. They are the main way to model records and domain-specific data in Tea.

A simple struct

Define a struct by naming the type and listing its fields. Each field carries an explicit type, which makes stored data predictable and easy to inspect at call sites.

struct User {
  name: String
  age: Int
}

Once the type exists, construct values with named fields and access those fields with dot syntax.

const user = User(name: "Ada", age: 36)

@println(user.name)
@println(user.age)

Structs in a larger example

Structs become more useful as programs grow. This example shows them alongside typed errors and formatted output in a longer file.

struct Team {
  name: String
  wins: Int
  losses: Int
}

error TeamError {
  NotFound(name: String)
}

const format_team = |team: Team| => `${team.name}: ${team.wins} wins / ${team.losses} losses`

const teams = [
  Team(name: "Ada", wins: 7, losses: 3),
  Team(name: "Grace", wins: 9, losses: 1),
  Team(name: "Linus", wins: 5, losses: 5)
]

Current model

The checked-in sources use struct, not classes. Construction is explicit, fields are named, and generic structs use square-bracket type parameters such as Box[T].

Next steps

Continue to

Generics

Apply type parameters to structs and functions.

Continue to

team_scoreboard

See a full struct-heavy example.