小编TLa*_*add的帖子

打字稿的深省略

Is it possible to maintain type coverage on a function that deeply removes all instances of a key in an object?

My function looks like this.

function omitDeep<T extends object>(obj: T, key: string): TWithoutProvidedKey {
  return JSON.parse(
    JSON.stringify(obj),
    (key: string, value: any) => key === "__typename" ? undefined : value
  );
}
Run Code Online (Sandbox Code Playgroud)

Is there any way to make TWithoutProvidedKey a reality?

typescript

5
推荐指数
3
解决办法
396
查看次数

标签 统计

typescript ×1