1
lodash的最新版本现在有一些新功能。例如:https://lodash.com/docs#nth。如何在打字稿中向现有对象添加声明
但lodash typings是旧版本,并没有这些功能。
import _ = require('lodash');
如何将这些函数的声明添加到_
对象?
lodash的最新版本现在有一些新功能。例如:https://lodash.com/docs#nth。如何在打字稿中向现有对象添加声明
但lodash typings是旧版本,并没有这些功能。
import _ = require('lodash');
如何将这些函数的声明添加到_
对象?
如果您检查分型文件,您可以看到基本LoDashStatic界面,你可以扩展:
import old = require('lodash')
interface LodashExt extends old.LoDashStatic {
nth(n: Array<any>, i: number) : LodashExt
// . . .
}
var _ = <LodashExt>old
_.add(1, 2)
_.nth(['a', 'b', 'c', 'd'], 2)
这应该是足够简单的案件。你可能想把上面的声明放到一个模块中,然后导出新的_值。
现在我正在这样做。但我希望没有新变量。 – wishmaster35