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
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 withnumber,string, orbooleanalready lower to native Rust primitives (f64,String,bool) in the emitted Rust source — noValueboxing 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.md→ Native compile (implementation status) in the language repo for current progress.