更新到6.3.3之后,我遇到了pipe()错误TS2557:预期至少有0个参数,但有1个或更多。

时间:2018-10-22 12:31:31

标签: javascript angular rxjs6

请有人可以帮助

在rxjs 6.3.3管道中的

获得TS2557:期望至少有0个参数,但有1个或更多。

   let currentPath;
const pipeArguments = path
  .map((subPath: string, index: number) => [
    flatMap((href: string) => {
      console.log('href', href);
      return this.getEndpointMapAt(href);
    }),
    map((endpointMap: EndpointMap) => {
      console.log('map', endpointMap);
      if (hasValue(endpointMap) && hasValue(endpointMap[subPath])) {
        currentPath = endpointMap[subPath];
        return endpointMap[subPath];
      } else {
        currentPath += '/' + subPath;
        return currentPath;
      }
    })
  ])
  .reduce((combined, thisElement) => [...combined, ...thisElement], []);
return of(this.getRootHref()).pipe(
  ...pipeArguments,
  distinctUntilChanged()
);

2 个答案:

答案 0 :(得分:0)

在与该问题相关的代码被合并之前,我认为您与此处看到的所有hack都一样,所以:here

issue

return (of('http://localhost:8001/1/') as any).pipe(
 ...pipeArguments,
 distinctUntilChanged()
);

答案 1 :(得分:0)

这是静态类型的问题。强制转换为any,但这是一个技巧。

类型安全的方法是在管道数组上reduce()

return pipeArguments
    .reduce((obs, op) => obs.pipe(op), of('http://localhost:8001/1/'))
    .pipe(distinctUntilChanged()

参考: