-
Notifications
You must be signed in to change notification settings - Fork 1
MS2 Type safety
GoogleFeud edited this page Feb 1, 2021
·
6 revisions
MS2 is a type-safe programming language, but it's type safety features are hidden. That means you cannot add variables of different types and get weird results like in javascript, or even worse - errors.
You should always provide typings to the objects you import. For example:
const Evaler = new MS2({
typings: {
imports: {
player: { type: OBJECT, properties: { name: STRING, id: NUMBER } },
someArr: { type: ARRAY, of: [STRING, NUMBER], readonly: true }
}
}
});Same for the export types. In order to make sure you are getting all the exports you need, specify them:
const Evaler = new MS2({
typings: {
exports: {
name: STRING,
someHook: {type: FUNCTION, returns: BOOLEAN, params: [STRING, NUMBER], allowNull: false}
}
}
});-
type- The type -
returns- Only applicable to functions, the return type of the function -
params- Only applicable to functions, the parameters of the function -
allowNull- If the import/export can benull -
properties- Only applicable to objects, the properties of the object -
of- Only applicable to arrays, the types of the values inside the array -
readonly- Only applicable to imported variables, if the variable can be overridden -
locked- Only applicable to imported objects, if any of the properties of the object can be modified