小编kaz*_*vac的帖子

NestJS-Mongoose:无法在 ChangeEvent<any> 上访问 fullDocument

我有以下基本代码片段,我的目标是从 获取 fullDocument 属性,obj: ChangeEvent但是我无法访问此属性 ( Property 'fullDocument' does not exist on type 'ChangeEvent<any>')。我可以访问的唯一属性是 _id、clusterTime 和 operationType。有什么我遗漏的,还是我应该非直接查询 fullDocument ( obj['fullDocument'])?

const changeStream = this.model.watch([], { fullDocument: 'updateLookup' })
      .on('change', obj => {
        console.log(obj.fullDocument);
      });
Run Code Online (Sandbox Code Playgroud)

model watch mongoose typescript nestjs

5
推荐指数
1
解决办法
112
查看次数

有没有办法提示 TS 泛型参数的出现用于泛型推理?

有没有办法提示 TS 泛型参数的出现用于泛型推理?

type Handler = <T>( // <-- if T is unspecified in method definition and call how can i tell ts to infer it to Ta from Params<Ta> and not Tb of the input?
  func: (params: Params<Ta>) => any,
  input: Tb
) => string;
Run Code Online (Sandbox Code Playgroud)

代码示例

type Params<T = Record<string, unknown>> = {
  p: T;
  // other metadata
}

type Handler = <T>( // <-- if T is unspecified how can i tell ts to infer it from Params<T>? …
Run Code Online (Sandbox Code Playgroud)

generics type-inference typescript

1
推荐指数
1
解决办法
235
查看次数

标签 统计

typescript ×2

generics ×1

model ×1

mongoose ×1

nestjs ×1

type-inference ×1

watch ×1