typescript - 如何帮助 Typescript 推断 PropertyDecorator 工厂函数的泛型参数?
问题描述
假设我有一个像这样的通用装饰器工厂:
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
// ^^^ Note: PropertyDecorator should be available as a built-in type with experimental decorators enabled.
export type Transformer<T, U> = (value: T) => U;
function PropertyTransformer<T, U>(to: Transformer<T, U>, from: Transformer<U, T>): PropertyDecorator {
return (target, propertyKey) => {
// Do some decorator stuff...
}
}
是否可以将类型限制T
为装饰属性恰好是(即T extends typeof target[propertyKey]
)的任何类型?
解决方案
推荐阅读
- javascript - 既然已经引入了类,为什么今天还有人使用 `let xyz = new Object()`?
- iis - 在 IIS 7.5 中托管的 .Net Remoting 服务中,如何删除“Server : IIS/7.5”标记表单响应头
- javascript - 按名称和最大类别从数组中删除重复对象
- asp.net - 使用公共 IP 地址和端口连接到数据库是否安全?
- delphi - 德尔福斐波那契数列
- c# - 如何分析数组的特定值并执行任务
- spring - 为什么我收到此错误 FUNCTION world.next_val 不存在
- python - 在许多文件上并行/调度python函数调用
- r - 安装 Rstudio 并启动它后,我收到一个 rsession.exe 系统错误,提示“Rlapack.dll 从您的计算机中丢失”
- highcharts - 在高图甘特图中垂直排列 yAxis 列的单元格