Skip to content

Types

Vibe has a simple but powerful type system designed for AI interactions.

TypeDescriptionExample
textString values"hello", 'world'
numberNumeric values (integers and decimals)42, -3.14
booleanBoolean valuestrue, false
jsonObjects and arrays{ key: "value" }, [1, 2, 3]
promptPrompt strings (compatible with text)Same as text
modelAI model configuration (immutable)Model declarations

You can optionally annotate variables with types:

let name: text = "Alice"
let age: number = 30
let active: boolean = true
let config: json = { timeout: 5000 }

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]]

Vibe can infer types from values:

let name = "Alice" // Inferred as text
let count = 42 // Inferred as number
let items = [1, 2, 3] // Inferred as number[]

Define named types with a specific structure:

type Person {
name: text
age: number
active: boolean
}
// Use in variable declarations
let user: Person = do "Create a person named Alice who is 30" model
// Access fields with type safety
print(user.name) // text
print(user.age) // number
if user.active {
print("User is active")
}

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
}
}

Use structural types in arrays:

type Player {
name: text
score: number
}
let leaderboard: Player[] = do "Get top 5 players" model
for player in leaderboard {
print("{player.name}: {player.score}")
}

Fields can be separated by commas, newlines, or both:

// Comma-separated (single line)
type Point { x: number, y: number }
// Newline-separated
type Config {
timeout: number
retries: number
debug: boolean
}
// Mixed
type Mixed {
a: text, b: number
c: boolean
}

When using AI expressions, the return type determines how the response is parsed:

// Returns a number
const count: number = do "How many continents are there?"
// Returns a boolean
const isPrime: boolean = do "Is 17 a prime number?"
// Returns an array of strings
const 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" model

The AI’s response is automatically validated and converted to the specified type. Structural types provide stronger validation than plain json.

Variables can hold null:

let maybeValue: text = null
let result = null

Note: null cannot be assigned to boolean variables in conditions.

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.