我有以下基本代码片段,我的目标是从 获取 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) 有没有办法提示 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)