RXJS 在管道运算符内将事件转换为 KeyboardEvent

Geo*_*tan 1 rxjs typescript angular

我正在尝试添加 keydown 事件并将参数类型从 Event 转换为 KeyboardEvent,但收到以下 TS 错误。

fromEvent(document, "keydown")
  .pipe<KeyboardEvent, KeyboardEvent>(
    filter((event) => event.code === "F5"),
    tap((event) => event.preventDefault())
  )
  .subscribe((ev) => {
    console.log(ev);
  });
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

error TS2345: Argument of type 'MonoTypeOperatorFunction<Event>' is not assignable to parameter of type 'OperatorFunction<Event, KeyboardEvent>'.
  Type 'Observable<Event>' is not assignable to type 'Observable<KeyboardEvent>'.
    Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, charCode, 
code, ctrlKey, and 17 more.
Run Code Online (Sandbox Code Playgroud)

有人遇到过这个问题吗?

mbo*_*jko 5

fromEvent也是通用的。

fromEvent<KeyboardEvent>(document, "keydown") // ...
Run Code Online (Sandbox Code Playgroud)