gpt4 book ai didi

javascript - RXJS 中的 startWith 运算符真的被弃用了吗?

转载 作者:行者123 更新时间:2023-12-01 14:46:32 24 4
gpt4 key购买 nike

自从更新到 RXJS 第 6 版后,我的 WebStorm 编辑器一直在提示 startWith() 的某些用法。该运算符被标记为已弃用。

您可以在源代码中看到这些方法被标记为已弃用:

  • Link to master ( Harder link for future )

  • 对我来说,问题是不推荐使用的警告不一致。有时它会报告已弃用的方法,有时则不会。虽然我可以在下面的代码示例中重现警告。它似乎随机发生在我自己的源代码中。

    未弃用:
      of(false).pipe(startWith(true));

    被标记为弃用:
      const x: any = true;
    of(false).pipe(startWith(x));

    所以我担心这些已弃用的警告。弃用消息说使用 scheduled()concat()运算符,但感觉比已经很方便的运算符(如 startWith())更复杂。 .

    所以我有点困惑为什么它被弃用,但为什么它有时只是被弃用。

    最佳答案

    不它不是。
    目前只有一个事件签名:startWith(...values)
    除了这个签名,它还有几个接受 scheduler: SchedulerLike 的重载。作为最新参数:startWith(...values, scheduler)并且此功能已被弃用。
    如果你不使用 schedulerstartWith你很好。
    如果你这样做了,那么你需要使用 scheduled 重写你的代码。功能就像他们在折旧注释旁边的评论中建议的那样:scheduled([[a, b, c], source], scheduler).pipe(concatAll()) .

    很有可能,您正在使用 startWith(null)startWith(undefined) ,尽管有通知,它们并未被弃用,但 IDE 检测到错误的函数签名,该函数签名已被弃用,并显示警告。
    或者,您正在使用 formControl.valueChanges发出 any类型,或任何其他带有 any 的可观察流.因为any匹配 SchedulerLike ,你看到通知。
    因此,尽量避免any通过添加 filter((v): v is number => typeof === 'number')或任何其他可能的方式。

    关于javascript - RXJS 中的 startWith 运算符真的被弃用了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56571406/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com