我在.ts文件中具有以下内容

module App.Filters {
    export class SplitRangeFilter implements ng.IFilterService {
        static $inject = ['$filter'];

        public static factory(): Function {
            return (input: string, splitIndex: number) => {
                return input.split('-')[splitIndex];
            }
        }
    }

    angular.module("App.Filters", []).filter('SplitRange', () => SplitRangeFilter.factory);
}

它给了我一个编译器错误:
Class SplitRangeFilter declared interface IFilterService but does not implement it: Types 'SplitRangeFilter' and 'IFilterService' have incompatible signatures. No matching signature for '<T>(name: string) => T'
我在angulars文档中找不到任何此类签名。有关如何摆脱VS2015中此编译器错误的任何建议

最佳答案

如果您只是想让它工作而又不关心实现“正确”的接口(interface),那么请删除implements ng.IFilterService,然后更改Angular注册语句以执行工厂(即添加())

angular.module("App.Filters", []).filter('SplitRange', () => SplitRangeFilter.factory());

关于javascript - 在Typescript中实现ng.IFilterService,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37059051/

10-12 15:09