node.js - 获取打字稿函数返回类型作为对象
问题描述
我实际上正在使用方法装饰器进行一些抽象。为此,我实际上想将函数的返回类型作为描述它的对象。不幸的是,我没有找到任何解决方案。
这是一个代码示例
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const routeArguments = handleFunctionMetadata(target, propertyKey, descriptor);
const route = {
path: path,
method: 'GET',
fn: descriptor.value.bind(this),
arguments: routeArguments
}
// I would like to get the return type of descriptor.value here
if (!target.paths) {
target.paths = {}
}
let key = _.findKey(target.paths, (v) => v === `${route.path}`);
const docPath = `/${route.path}`;
const __swaggerRoute = {
'get': {
consumes: ["application/json"],
produces: ["application/json"],
"summary": "",
"description": "",
}
}
if (!key) {
target.paths[docPath] = __swaggerRoute
} else {
target.paths[docPath] = _.merge(
target.paths[docPath],
__swaggerRoute
)
}
if (!target.routes)
target.routes = [route];
else if (_.isArray(target.routes))
target.routes.push(route)
return descriptor;
};
解决方案
推荐阅读
- swift - 广泛的 Swift 扩展协议
- php - mkdir 无法处理文件夹内的 php
- c# - 如何使用 BFS 在 6x6 网格迷宫 C# 中找到最短路径
- reactjs - Store.subscribe:TypeError:__webpack_require__.i(...) 不是函数
- symfony - LexikJWTAuthenticationBundle 始终通过令牌存储获取空用户
- r - R - 替换正则表达式匹配的最后一个实例以及之后的所有内容
- javascript - 如何获取 Angular 2 中 div 中所有元素的引用?
- javascript - 使用 jQuery 在提交时显示/隐藏表单
- java - Java GUI Temp Calculator W/Two JButtons (Cel/Fah) Jlabel5 中的 Calc 输出?
- tensorflow - 激活函数的选择