Motivation
Functions in JavaScript is flexible, indeed it does not enforce parameter and return type.
In order to ensure correctness of program, typechecking for function refinement is needed.
Typechecking Rules
The rule for checking type validity for function refinement is simple, output(return) type of function must be covariant(subtyped) for input(parameter) of succeeding function. In other words, input(parameter) of function should be contravariant for its argument(returned data from preceding function)
Type Lists
Below table shows list of supported types
| Name |
Notation |
| Boolean Type |
boolean |
| Number Type |
number |
| String Type |
string |
| Array Type |
array |
| Any Type |
any |
| Null Type |
null |
| Undefined Type |
undefined |
| Intersection Type (traits) |
Object.assign(typeA, typeB) |
| Union Type (priority type) |
typeA|typeB|typeC |
| Optional Type |
?typeA |
Examples
Motivation
Functions in JavaScript is flexible, indeed it does not enforce parameter and return type.
In order to ensure correctness of program, typechecking for function refinement is needed.
Typechecking Rules
The rule for checking type validity for function refinement is simple, output(return) type of function must be covariant(subtyped) for input(parameter) of succeeding function. In other words, input(parameter) of function should be contravariant for its argument(returned data from preceding function)
Type Lists
Below table shows list of supported types
booleannumberstringarrayanynullundefinedObject.assign(typeA, typeB)typeA|typeB|typeC?typeAExamples