RuntypeScript
Comments
// Only single line comments
Declarations
var x = y; var x: T = y; const x = y; const x: T = y;
Declaration with no declared type:
const x = y;
is a shorthand for:
const x: ~y = y;
except that y is evaluated only once.
Declaration cannot shadow other variables.
Assignment
Left-hand side of an assignment can only consist of an identifier followed by an optional chain of indexing expressions. Indexes themselves can be arbitrary expressions.
An assignment results in a runtime error if a variable after assignment (including mutation) is not assignable to its declared type.
const x: { prop: string } = { prop: "foo" }; // allowed x["prop"] = "bar"; // not allowed, { prop: 1 } not assignable to { prop: string } x["prop"] = 1;
You can also use the following assignment shorthands:
- +=
- -=
- *=
- /=
- %=
- |=
- &=
If, elif, else
if (CONDITION) { // (...) } elif (CONDITION) { // (...) } else { // (...) }
Braces are always required.
While
while (CONDITION) { // (...) }
Braces are always required.
You can use break and continue statements inside a while loop.
Return
return EXPRESSION; return; // shorthand for return nil;