英文:
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<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论