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 (no runtime type errors for mismatches).
  • --native-backend rust: Variable declarations annotated with number, string, or boolean already lower to native Rust primitives (f64, String, bool) in the emitted Rust source — no Value boxing for those bindings. Function parameters with type annotations similarly emit typed Rust parameters.
  • Inference (in progress): The compiler is gaining a type-inference pass that propagates primitive types through arithmetic, loop counters, and homogeneous array literals automatically, so you get native codegen without having to annotate everything manually. See docs/LANGUAGE.mdNative compile (implementation status) in the language repo for current progress.

Improve this documentation