How do you lock a variable as to only accept int , string , bool ..etc? such as :
var test : int = 0;
var test2 : String = "test";
is it possible?
How do you lock a variable as to only accept int , string , bool ..etc? such as :
var test : int = 0;
var test2 : String = "test";
is it possible?
Well, it is not possible to do with raw Node.js, because it is just a runtime for JavaScript. If you want to have strong types you should use TypeScript.
Here is useful reading for you on how to set up Node.js project with TypeScript https://blog.logrocket.com/typescript-with-node-js-and-express/
JavaScript do no have types. Your can implement a "custom base class" to self verify values of yours properties, before set a value.
Other option is TypeScript: https://www.typescriptlang.org/