【问题标题】:Argument of type '(_spaceService_: any) => any' is not assignable to'(_spaceService_: any) => any' 类型的参数不可分配给
【发布时间】:2018-03-19 06:33:18
【问题描述】:

嘿,如果我在我的代码库中更新以下代码,我会收到以下错误,你能告诉我如何修复它吗?在下面提供我的代码和错误

let spaceService;
            beforeEach(inject(function(_spaceService_, ''){
                spaceService = _spaceService_
            ));

Argument of type '(_spaceService_: any) => any' is not assignable to pramter of type 'any[]'.

类型“(spaceService:any) => any”中缺少属性“push”。

【问题讨论】:

  • 错误句的其余部分是什么?
  • @ZivWeissman 感谢您的回复...更新了完整的错误
  • 所以基本上你有你需要的答案 - spaceService 是一个数组,所以你可以使用 spaceService.push(/_spaceService_/) 或 spaceService[0] = /_spaceService_/ - 为什么 spaceService 是一个数组?
  • @ZivWeissman 你能在我的代码中更新一下吗,太令人困惑了:(
  • 我已经添加它作为答案我希望它更清楚,你可能需要弄清楚你是否需要数组。

标签: javascript jquery html angularjs typescript


【解决方案1】:

问题是由于某种原因(可能来自代码的不同部分)变量 spaceService 是一个数组,因此您需要将代码更改为以下内容:

let spaceService; 
// if it is not initiated you should use:
//let spaceService: any[] = new array[];
            beforeEach(inject(function(_spaceService_, ''){
                spaceService.push(_spaceService_);
            ));

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 2020-03-19
    • 2019-01-09
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2018-04-23
    • 2018-08-30
    相关资源
    最近更新 更多