Typing

Typing

> LeekScript

Since update 2.38, it is possible to use types in LeekScript.

Types

Compound Types

Use the | sign to create compound types, for example integer | string represents a value which can be either an integer or a string.

It is possible to combine as many types as desired: integer | boolean | string | Array for example.

To write a compound type with null, for example Array | null, it is possible to write Array?.

Typing a variable

Typing a function

standard function
lambda function (anonymous)

Typing a for loop

Typing a class field

Typing a method

Typing operators

! operator

The ! operator converts a value type by removing the null type. It will not convert the actual value. For example, for a type integer | null:

It is possible to use it in an object access chain: object.toto!.tutu But if objet.toto is null, then it will crash on execution. The main use of this operator is removing warnings in strict mode and assert that a type is not null on execution.

as operator

The as operator converts a value to any type, if possible: