>Tish
HomeDocs

Type Annotations

Optional TypeScript-style type annotations in Tish.

Tish supports optional TypeScript-style type annotations. Types are parsed but not enforced at runtime (gradual typing). Omit them for dynamic typing.

Syntax

// Variable declarations
let x: number = 42
const name: string = "hello"
let arr: number[] = [1, 2, 3]
 
// Function parameters and return types
fn add(a: number, b: number): number {
    return a + b
}
 
// Object types
let person: { name: string, age: number } = { name: "Alice", age: 30 }
 
// Union types
let value: number | string = 42
 
// Rest parameters
fn sum(...args: number[]): number { ... }

Supported Types

TypeDescription
numberNumeric values (f64)
stringString values
booleantrue or false
nullThe null value
voidNo return value (functions)
T[]Array of type T
{ k: T }Object with typed properties
T | UUnion (either T or U)
(T) => RFunction type (syntax only, future)

Notes

  • Type annotations are optional; omitting them is equivalent to dynamic typing.
  • Types are parsed and stored in the AST but not enforced during evaluation.
  • Future phases may add type inference and type checking.