RuntypeScript
Binary operators
Operator | Applicable to | Description |
---|---|---|
+ | number literals | addition |
+ | string literals | concatenation |
- | number literals | subtraction |
* | number literals | multiplication |
/ | number literals | division |
% | number literals | modulo |
== | all types | type equality |
!= | all types | type inequality |
> | number literals | comparison |
>= | number literals | comparison |
< | number literals | comparison |
<= | number literals | comparison |
and | false or true | logical and |
or | false or true | logical or |
| | all types | type union |
& | all types | type intersection |
extends | all types | type assignability |
Unary operators
Operator | Applicable to | Description |
---|---|---|
- | number literals | negation |
# | tuples | tuple length |
~ | all types | deliteralization |
not | false or true | logical not |
decltype | identifiers | declared type |
Operator priority
Priority | Operators |
---|---|
0 | or |
1 | and |
2 | < > <= >= == != extends |
3 | | |
4 | & |
5 | + - (binary) |
6 | * / % |
7 | - (unary) not # ~ decltype |
Identifier
An identifier starts with a letter (as defined by Unicode Letter category) or underscore optionally followed by a sequence of letters, numbers (as defined by Unicode Letter, Decimal Number and Letter Number categories) and underscores, and is not one of the reserved keywords:
- and
- break
- const
- continue
- decltype
- elif
- else
- extends
- fn
- if
- not
- or
- return
- sig
- var
- while
Keep in mind that there are also predefined global constants, and that shadowing is forbidden.
Function call
Function is called with a set of round brackets. Arguments are seperated by a comma. Leading comma is permitted.
Argument count has to match exactly or a runtime error will occur.
const add = fn (a: number, b: number) number { return a + b; }; println(add(1, 2)); println(add(1, 2, 3)); // wrong println(add(1, "foo")); // also wrong
Indexing
Indexing is performed with a set of square brackets. You can index tuples with number literals or objects with string literals.
const array: number[] = []; array[0] = 1; const object: any = {}; object["foo"] = "bar";
Note that there is no shorthand notation (i.e. dot notation) for accessing object properties.
Literals
Check the documentation about type system to learn about literals.