# Type declaration

When declaring a variable and declaring a function parameter, you can declare the variable type at the same time. If the function parameter does not display the declared type, the default is the object type

E.g:

let a: string = "123"
var b: G1                          -- G1 is a record type
let b: int | string | Person       --   Person is a record type, this statement indicates that b is int or string or Person type, that is, union type
let c ?: int                       --  This indicates that the declared variable c is of type int or nil, which is equivalent to the union type of int | nil

let function add(a: number, b: number, c ?: Array<number>)
    return a + b
end

You can also declare the function type when declaring the type. The function's signature type syntax is (ArgTypeName1,…) => RetTypeName

E.g:

let a: (int, int, int) => string

You can also declare the type of a variable or function parameter as a Function, indicating that the type of this variable/parameter is a function and can accept any function type value, regardless of the number of parameters, parameter type, and return value type.

E.g:

let function add(a: number, b: number)
    return a + b
end
let add2: Function = add
let r = add2('123')    -- The type of this code is no problem at compile time, but the type error will be reported at runtime