最近我一直在尝试使用 欠款 库,但我收到了警告。在本地声明'_',但不输出。 当我试图在最近创建的HelperService中使用它时。
在安装时,我尝试了npm install underscore还npm install -g typescript@next然后npm install --save underscorenpm install --save @typesunderscore
该警告显示在下划线的 import import { _ } from 'undererscore'中。
从'下划线'导入 { _[就在这里] *} *from 'undererscore';**。
这是HelperService的完整代码。
import { Injectable } from '@angular/core';
import { _ } from 'underscore';
@Injectable({
providedIn: 'root'
})
export class HelperService {
constructor() { }
public each(array, delegate) {
return _.each(array, delegate);
}
public without(array, delegate) {
return _.without(array, delegate);
}
}
该服务位于路径中: *Users/workspace/srcserviceshelperhelper.service.ts
*Users/workspace/srcserviceshelperhelper.service.ts。
这是完整的警告:模块'"......Users/workspace/node_modules@typesunderscore"'声明''......Users/workspace/node_modules@typesunderscore''。'在本地,但它没有被导出.ts(2459)index.d.ts(14, 13): ''是在这里声明的.index.d.ts(24,16):和这里。
如何才能让我认识到 从'undererscore'导入{ _ }。 正确吗?
如果有任何帮助,我将不胜感激
试着使用这个语法 -
import { * as _ } from 'underscore';
添加 declare module 'underscore';
在你 index.d.ts
档案