English 中文(简体)
如何确定/分析这种特定(最好是一般)的文字汇编错误?
原标题:How to fix/debug this particular (and preferably in general) TypeScript compilation error?

I have this TypeScript code (it s dirty, with comments because I decided to leave them to show various approaches I ve tried):

function getPlacesToStopExchange(): {
  our: { i: number; val: number; }[];
  enemy: { i: number; val: number; }[];
  //[party in  our  |  enemy  ]: { i: number; val: number; }[];
} {
  return valuesByMoves.reduce((o, v, i) => {
    if (i === 0 || i % 2) {
      //  //we move
      const el: { i: number; val: number; } = { i, val: v, };
      o.enemy.push(el);
    } else {
    //  o.our.push({ i, val: v, } as { i: number; val: number; }));
    }
    return o;
  }, { enemy: [], our: [], });
}

第10行:o.enemy.push(el); I m 发现这一错误:

error TS2345: Argument of type  { i: number; val: number; }  is not assignable
to parameter of type  never .

134           o.enemy.push(el);

如果我这样说——没有出现错误,那么我很相信它确实如此,而不是在职能申报的类型上,回报值或初始价值下降。

www.un.org/Depts/DGACM/index_spanish.htm 是否有任何人知道如何解决这一问题? 我看到了关于SO的其他问题,实际上说,我必须具体说明发生错误的地点类型,但因为我可以看到我以多种方式尝试了这一问题。

我还试图研究<代码>tsc代码,但没有点名。 因此,我不知道什么地方。

∗∗∗∗∗ 我非常感谢错误。

谢谢。

问题回答

这有助于确定减少反馈的初步价值:

function getPlacesToStopExchange(): {
  our: { i: number; val: number; }[];
  enemy: { i: number; val: number; }[];
  //[party in  our  |  enemy  ]: { i: number; val: number; }[];
} {
  return valuesByMoves.reduce((o, v, i) => {
    if (i === 0 || i % 2) {
      //  //we move
      const el: { i: number; val: number; } = { i, val: v, };
      o.enemy.push(el);
    } else {
    //  o.our.push({ i, val: v, } as { i: number; val: number; }));
    }
    return o;
  }, { enemy: [], our: [], } as {
    our: { i: number; val: number; }[];
    enemy: { i: number; val: number; }[];
    //[party in  our  |  enemy  ]: { i: number; val: number; }[];
  });
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签