繁体   English   中英

如何在返回与 object 实例相同类型的 Obect 原型上声明 typescript 属性

[英]How to declare a typescript property on Obect prototype that returns the same type as the object instance

我将此属性添加到我的 Object 原型中:

declare global {
  interface Object {
    // how can i declare that the result is not just any 
    // but the very same type as the object instance?
    get stripped(): any 
  }
}

我不想返回任何我想声明剥离返回的 object 类型与 object 实例完全相同。 我怎样才能做到这一点?

不太相关,但此属性会删除所有值为 undefined 的属性。

使用这个参数:

stripped<T>(this: T): T,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM