Types
Vibe has a simple but powerful type system designed for AI interactions.
Base Types
Section titled “Base Types”| Type | Description | Example |
|---|---|---|
text | String values | "hello", 'world' |
number | Numeric values (integers and decimals) | 42, -3.14 |
boolean | Boolean values | true, false |
json | Objects and arrays | { key: "value" }, [1, 2, 3] |
prompt | Prompt strings (compatible with text) | Same as text |
model | AI model configuration (immutable) | Model declarations |
Type Annotations
Section titled “Type Annotations”You can optionally annotate variables with types:
let name: text = "Alice"let age: number = 30let active: boolean = truelet config: json = { timeout: 5000 }Array Types
Section titled “Array Types”Append [] to any base type for arrays:
let names: text[] = ["Alice", "Bob"]let scores: number[] = [95, 87, 92]let flags: boolean[] = [true, false, true]Arrays can be nested:
let matrix: number[][] = [[1, 2], [3, 4]]Type Inference
Section titled “Type Inference”Vibe can infer types from values:
let name = "Alice" // Inferred as textlet count = 42 // Inferred as numberlet items = [1, 2, 3] // Inferred as number[]Structural Types
Section titled “Structural Types”Define named types with a specific structure:
type Person { name: text age: number active: boolean}
// Use in variable declarationslet user: Person = do "Create a person named Alice who is 30" model
// Access fields with type safetyprint(user.name) // textprint(user.age) // numberif user.active { print("User is active")}Nested Types
Section titled “Nested Types”Types can reference other types or have inline nested structures:
type Address { city: text country: text}
type Employee { name: text address: Address // Reference another type metadata: { // Inline nested object hireDate: text department: text }}Arrays of Types
Section titled “Arrays of Types”Use structural types in arrays:
type Player { name: text score: number}
let leaderboard: Player[] = do "Get top 5 players" modelfor player in leaderboard { print("{player.name}: {player.score}")}Flexible Field Separators
Section titled “Flexible Field Separators”Fields can be separated by commas, newlines, or both:
// Comma-separated (single line)type Point { x: number, y: number }
// Newline-separatedtype Config { timeout: number retries: number debug: boolean}
// Mixedtype Mixed { a: text, b: number c: boolean}AI Return Types
Section titled “AI Return Types”When using AI expressions, the return type determines how the response is parsed:
// Returns a numberconst count: number = do "How many continents are there?"
// Returns a booleanconst isPrime: boolean = do "Is 17 a prime number?"
// Returns an array of stringsconst languages: text[] = do "List 5 programming languages"
// Returns a structured object (untyped)const person: json = do "Return a person with name and age fields"
// Returns a structured object (typed - recommended)type Person { name: text, age: number }const typedPerson: Person = do "Return a person with name and age" modelThe AI’s response is automatically validated and converted to the specified type. Structural types provide stronger validation than plain json.
Null Values
Section titled “Null Values”Variables can hold null:
let maybeValue: text = nulllet result = nullNote: null cannot be assigned to boolean variables in conditions.
Model Type
Section titled “Model Type”The model type is special—it’s always immutable and used for AI configuration:
model assistant = { name: "claude-sonnet-4-20250514", provider: "anthropic", apiKey: env("ANTHROPIC_API_KEY")}See Models for more details.