【发布时间】:2015-11-03 14:36:21
【问题描述】:
我的 TypeScript 1.5 + AngularJS 1 项目中有以下过滤器:
module Filters{
export function percentage($filter:angular.IFilterService) {
return function(input: number, decimals: number): string{
return $filter('number')(input * 100, decimals) + '%';
}
}
var app = AppModule.getModule();
app.filter("percentage", Filters.percentage);
}
它假设将输入更改为百分比值 - 我知道,我可以用不同的方式来做,但它与过滤器本身无关 - 它与为过滤器分配类型有关。
使用以下代码,我在编译过程中收到以下错误:
error TS2345: Argument of type 'number' is not assignable to parameter of type '{}[]'.
Property 'length' is missing in type 'Number'.
这在打字中指出了这一点:
interface IFilterService {
/**
* Usage:
* $filter(name);
*
* @param name Name of the filter function to retrieve
*/
(name: string): IFilterFunc;
}
interface IFilterFunc {
<T>(array: T[], expression: string | IFilterPatternObject | IFilterPredicateFunc<T>, comparator?: IFilterComparatorFunc<T>|boolean): T[];
}
但是,我不确定是什么问题。有任何想法吗?
【问题讨论】:
-
也许这会帮助stackoverflow.com/a/33064403/99256。但是,我无法以某种方式重现您的问题。
标签: angularjs typescript