RuntypeScript

Type system is the value system

Types and values are mixed with each other, so using the terms type and value interchangeably can get confusing (because they aren't different things in this language). Since these value/type hybrids work more like types than values, we will refer to them only as types on this page.

nil

Nil represents nothing. It is returned by a function when nothing is returned explicitly.

false, true

False and true are the results of comparison operators and can be used as operand for logical operators.

boolean

Boolean is a union of false and true.

string

String is a union of every possible string literal.

String literals

String literals are enclosed in double quotes. You can make use of the following escape sequences in a string literal:

number

Number is a union of every possible number literal.

Number literals

Number literals are double presicion floating-point. Only decimal literals are supported (no hexadecimal or exponentials).

Typed array

Typed array is defined by specifying its element type. Type array is a union of every possible tuple, for which every element is assignable to typed array's element type. You can turn any type into a typed array by appending a pair of square brackets after the type.

const array_of_number = number[];
const array_of_zero_or_foo = (0 | "foo")[];
const array_of_array = any[][];

Tuple

Tuples are arrays of types and are indexed by number literals.

const tuple = [number, string];
const also_tuple = [0, 1, 2, fn () nil {}, boolean, [number, "foo"]];

Tuples are passed by reference and are mutable.

Object

Objects can hold multiple properties and are indexed by string literals.

const empty_obj = {};
const simple_obj = { foo: "bar", baz: string[] };
const nested_obj = { foo: {}, baz: [{}] };

Signatures

Signatures are specified by a list of argument types and a return type. A signature is a union of every possible function assignable to that signature.

const binary_sig = sig (any, any) any;
const filter_sig = sig (any[], sig (any) boolean) any[];

Signatures never contain names of arguments.

Functions

Every function is its own distinct type tied to its literal.

const concat = fn (a: string, b: string) string { return a + b; };

Function arguments are not constants and can be reassigned inside the function body. A function will capture its outside scope.

There are intrinsic functions in this language, which are global constants and their function bodies are implemented in the interpreter itself instead of the language. They cannot be created by language users.

Unions

Unions represents a type, to which many other types are assignable. You can create unions using "|" operator. Unions do not nest (a union of unions collapses into a single union) and are immutable.

any

Any is a union of every possible type in this language, including itself.

Deliteralization

Deliteralization is a transformation of types, that is performed to determine the declared type when none was provided. You can use unary "~" operator to perform the same process yourself. Deliteralization rules:

Assignability

Assignability is a process that determines whether a type can be assigned to a variable's declared type. You can use binary "extends" operator to perform the same process yourself. Assignability rules: