Node.js 方法的Nodejs、DTO、输入类型和返回类型
如何在nodejs中尽可能接近以下3个功能Node.js 方法的Nodejs、DTO、输入类型和返回类型,node.js,dto,Node.js,Dto,如何在nodejs中尽可能接近以下3个功能 // 1./ namespaces for types, so I don't need to have long type names import foo.bar.Type1; import foo.bar.Type2; ... // 2./ strict complex types of method parameters // 3./ strict complex type for return type public function fo
// 1./ namespaces for types, so I don't need to have long type names
import foo.bar.Type1;
import foo.bar.Type2;
...
// 2./ strict complex types of method parameters
// 3./ strict complex type for return type
public function foo(Type1 param1, Type2 param2): Type3 {
...
}
这都是关于在我们的项目中引入DTO的能力,如果没有它,这将变得非常混乱:(
处理DTO的nodejs行业标准是什么
foo >
bar >
Type1.js
Type2.js
然后可以通过以下方式导入:
const Type1 = require('./foo/bar/Type1');
const Type2 = require('./foo/bar/Type2');
typeof
操作符来确定传递到函数中的类型,并拒绝不满足类型要求的调用function test(someString, someNum, someObject) {
if ( typeof someString != 'string' ||
typeof someNum != 'number' ||
typeof someObject != 'object' )
{ return false; }
// Execute function
return true;
}
谢谢您的回答!我将明确检查ESlint。对于静态分析和类型强制,我将在最后可能使用TypeScript或Flow。