【问题标题】:type 'void' has no property 'blob' and no string index signature“void”类型没有属性“blob”,也没有字符串索引签名
【发布时间】:2018-03-27 05:22:38
【问题描述】:

Update1:​​我根据 Pankaj 的回答更新了代码

嘿,我在代码库中更新了您的代码...但我仍然收到这样的错误...任何想法...在分号结尾 [ts] 预期属性分配。

Observable.fromEvent( $("#AnimalRatsGrid .RatNameFile"), "click")
          .do((e) => {
            console.log("I am here");
            alert("I am here");
            kendo.ui.progress($("#loading"), true);
          }).map(e => "Rats/color/black?RatId="+"7887878787")
          .mergeMap(vals => that.nbcuService.getResponse(vals, 'get', ""))
          //.map(data => { blob: new Blob([data], { type: 'application/octet-stream' }), fire: "untitled1.txt" })
          .map(data => {
              //creating customData object
              let customData: any = {
                  blob: new Blob([data],
                  {
                    type: 'application/octet-stream'
                  }),
                  fire: "untitled1.txt" //
              };
              return customData; //returning it from map.
            })
          .subscribe(
            ({blob, fire}) => that.nbcuService.saveAs(blob,fire),
            err => { }
          );
        });
  • 我正在努力学习 rxjs。
  • 所以我包含了 rxjs 方法。
  • 但我的视觉工作室出现三个错误。

    // [ts] 未使用的标签。 // [ts] 找不到名称 'fire'.any //[ts] 类型 'void' 没有属性 'blob' 也没有字符串索引签名。

  • 你能告诉我如何解决吗..

  • 在下面提供我的相关代码。
  • 我在要点https://gist.github.com/texirv0203/e071a9ebea3a6aa0f8a0c65d47f75807给出的整个代码
Observable.fromEvent($("#AnimalRatsGrid .RatNameFile"), "click")
  .do((e) => {
    console.log("I am here");
    alert("I am here");
    kendo.ui.progress($("#loading"), true);
  }).map(e => "Rats/color/black?RatId=" + "7887878787")
  .mergeMap(vals => that.sportsservice.getResponse(vals, 'get', ""))
  .map(data => {
    blob: new Blob([data], // [ts] Unused label.
      {
        type: 'application/octet-stream'
      }),
    fire: "untitled1.txt" //  [ts] Cannot find name 'fire'.any
  })
  .subscribe(
    //[ts] Type 'void' has no property 'blob' and no string index signature.
    ({
      blob,
      fire
    }) => that.sportsservice.saveAs(blob, fire),
    err => {}
  );
});

【问题讨论】:

    标签: javascript html angular typescript rxjs


    【解决方案1】:

    Typescript 之所以大喊大叫,是因为可观察到的最后一部分,即 map 函数不会返回任何 void 对象。当你有像 .map(item => item.someProp) 这样的 lambda 表达式时,lambda 隐式返回 RHS,当你在 lambda 函数中使用 { }(括号)时,你必须显式地从 function 返回所需的结果。

    .map(data => {
      //creating customData object
      let customData: any = {
          blob: new Blob([data],
          {
             type: 'application/octet-stream'
          }),
          fire: "untitled1.txt" //
       };
       return customData; //returning it from map.
    })
    

    【讨论】:

    • 嘿,我在代码库中更新了您的代码...但我仍然收到这样的错误...任何想法...在分号结尾 [ts] 预期的属性分配。-- -------> 也更新问题中的代码
    猜你喜欢
    • 2018-09-11
    • 2018-12-15
    • 2020-10-11
    • 1970-01-01
    • 2023-03-05
    • 2020-07-09
    • 2017-03-20
    • 2019-05-23
    • 2019-04-06
    相关资源
    最近更新 更多