Skip to Content

Type Alias

typealias gives an existing type a new name.

Type Aliases

An alias is fully transparent: the new name is the original type itself, and assignment, operators, and is tests all interoperate with the original type.

typealias Meters = int; typealias StrList = list<string>; func main() -> int { val m: Meters = 5; print(m + 1, m is int); val plain: int = m; print(plain); val xs = new StrList(); xs.Add("a"); print(xs[0], xs.Count); return 0; }
6 True 5 a 1

Array aliases work the same way: after typealias Row = int[];, val r: Row = [1, 2, 3]; is legal and r is int[] is True. Generic aliases take type parameters and are used instantiated:

typealias Pair<T, U> = (T, U); func main() -> int { val p: Pair<int, string> = (7, "seven"); print(p.Item0, p.Item1); return 0; }
7 seven

Alias cycles are rejected at compile time with MS3114:

error MS3114: Type alias cycle: A → A.

An alias only creates a new name, not a new type: Meters and int are the same type in the type checker, with no difference in conversion, equality, or overload dispatch. If you want the discipline of “renamed means not mutually assignable”, an alias cannot give you that; it is the domain of the host-boundary opaque handle, see Host Boundary.

Notes

  • Aliases are declared at module top level;
  • Aliases can be used in type annotation positions, generic argument positions, and construction positions; is tests answer with the original type;
  • typealias is a soft keyword at the declaration-start position, and name positions like val typealias = 1 remain legal; the retired type is now fully free and works as an ordinary identifier (val type = 7 is legal).
Last updated on October 11, 2026