2016-08-09 11 views
0

何らかの理由で、私はIDE(IntelliJ)にこの問題について不平を言ってもらえませんでした。私はmemoizeは、パラメータとしての機能を取ることができると思った:Lodash _.memoize "引数の型がパラメータと一致しません"

declare var _: _.LoDashStatic; 

export class MemoizeService { 
    'use strict'; 

    masterCatTree; 
    ... 

    flattenTree = _.memoize(this._flattenTree); 
    private _flattenTree(tree?: any, level?: number) { 
     let level; 
     const self = this; 
     if (!tree) { 
      tree = self.masterCatTree; 
      level = 0; 
     } 

     let arr = []; 
     if (tree) { 
      for (let key in tree) { 
       if (!tree.hasOwnProperty(key)) { 
        continue; 
       } 
       let val = angular.copy(tree[key]); 
       if (level) { 
        val.name = _.times(level, _.constant('-')).join('') + ' ' + val.name; 
       } 
       arr.push(val); 
       arr.push(...self.flattenTree(val.children, level + 1)); 
      } 
     } 
     return arr; 
    } 

/*補足*/

LodashStaticが

interface LoDashStatic { 
    /** 
    * Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for 
    * storing the result based on the arguments provided to the memoized function. By default, the first argument 
    * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with 
    * the this binding of the memoized function. 
    * @param func The function to have its output memoized. 
    * @param resolver The function to resolve the cache key. 
    * @return Returns the new memoizing function. 
    */ 
    memoize: { 
     <T extends Function>(func: T, resolver?: Function): T & MemoizedFunction; 
     Cache: MapCache; 
    } 
} 
+0

最新のlodash.d.tsを使用していて、それを参照していますか( '///

+0

@MikeMcCaughanを見ていただきありがとうございます。質問のコードを修正しました。 'declare var _:_.LoDashStatic; 'を使用しています。 – ThinkBonobo

+0

また、' _.memoize'の代わりに '_.once'を使用したときに私はそのようなエラーを表示しませんが、私の機能では、一度使う。 – ThinkBonobo

答えて

0

の代わりに頼っ定義ファイルに次の情報を持っていますグローバル宣言では、モジュール宣言ファイルtypings install --save lodashをいつでもインストールできます。ファイルの先頭に明示的にimport * as _ from 'lodash'が記載されている場合は、var _: _.LodashStaticではなくすべてが正常であるはずです。

関連する問題