我在我的打字稿以下过滤器1.5 + AngularJS 1项目:打字稿+角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[];
}
不过,我安静不知道什么是问题。有任何想法吗?
也许这将有助于http://stackoverflow.com/a/33064403/99256。但是,我无法以某种方式重现您的问题。 –