使用闭包代替 `thisArg`?问题出现在 .pipe(map(

huangapple go评论59阅读模式
英文:

Use a closure instead of a `thisArg`? Issue with .pipe(map(

问题

以下是要翻译的代码部分:

我拥有的代码已经被标记为不推荐使用我想知道是否有人可以帮助我更新它

问题出在地图部分

/** @deprecated 使用闭包代替 `thisArg`。在 v8 中将删除接受 `thisArg` 的签名。 */


public getDetails(): any 
  {
    return this.apiService.findForm().pipe(map((response: any) => {

      return response;
    },
      err => {

        return err;
      }
    ));
  }

非常感谢
英文:

The code I have is marked deprecated, I'm wondering if anyone could help me update it.

The issue is with the map part.

/** @deprecated Use a closure instead of a thisArg. Signatures accepting a thisArg will be removed in v8. */

public getDetails(): any 
  {
    return this.apiService.findForm().pipe(map((response: any) => {

      return response;
    },
      err => {

        return err;
      }
    ));
  }

Many Thanks

答案1

得分: 3

Separating the two arguments to map fixes this:

return this.apiService.findForm()
.pipe(
map((response: any) => { return response; }),
catchError((err) => { return err; })
)

英文:

Separating the two arguments to map fixes this:

return this.apiService.findForm()
  .pipe(
     map((response: any) => { return response; }),
     catchError((err) => { return err; })
  )

答案2

得分: 0

根据我在rxjs代码中所见,只要不使用map的第二个签名,这个弃用就与您无关。

export function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
/** @deprecated 使用闭包而不是`thisArg`。接受`thisArg`的签名将在v8中移除。 */
export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;
英文:

As I can see in rxjs code, as long as you don't use the map with the second signature, this deprecation doesn't concern you.

export function map&lt;T, R&gt;(project: (value: T, index: number) =&gt; R): OperatorFunction&lt;T, R&gt;;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function map&lt;T, R, A&gt;(project: (this: A, value: T, index: number) =&gt; R, thisArg: A): OperatorFunction&lt;T, R&gt;;

huangapple
  • 本文由 发表于 2023年5月29日 17:31:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356183.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定