【问题标题】:Missing interface declaration for _.split in Lodash.d.tsLodash.d.ts 中 _.split 的接口声明缺失
【发布时间】:2016-07-18 00:21:48
【问题描述】:

我正在开发一个广泛依赖 Lodash(使用 lodash.d.ts)的打字稿项目。我已经实现了一个使用_.split 函数的方法,但这似乎还没有实现。 (参考 .ts 文件,它包含在“稍后”部分中)。

有没有办法让我解决这个问题,所以它不会停止我的构建? (从 Visual Studio 构建,有时作为 Grunt 任务)。

这是错误:

TS2339 Property 'split' does not exist on type 'LoDashStatic'

作为上下文参考,代码如下:

private parseString(text: string) {
    const arr = _.map(_.split(text, ","),
        (x: string) => {
            let index = x.indexOf(":");
            return [
                x.substring(0, index),
                _.trim(x.substring(index + 1), "()")
            ];
        });

    console.log(_.fromPairs(arr));

    return _.fromPairs(arr);
}

代码可以工作,但是构建因此停止,这很烦人。

【问题讨论】:

标签: javascript typescript lodash


【解决方案1】:

使用原生 Javascript string.split() 方法以“简单”的方式解决了这个问题。

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2018-09-15
    • 2018-03-30
    • 1970-01-01
    • 2014-09-20
    • 2011-09-15
    • 2019-07-16
    • 2021-12-01
    • 1970-01-01
    相关资源
    最近更新 更多