javascript - 如何排除 getter 和 setter?
问题描述
考虑下面的类Foo
:
class SomeClass {
}
class Foo {
readonly foo: string
readonly baz?:string
private someclass: SomeClass
set bar(v:boolean){
// th is.foo = v
}
getFoo() {
}
constructor(json: FooLike) {
this.foo = json.foo
this.baz = json.baz
this.someclass = json.someclass
}
}
我的目标是获得类似这样的界面
interface FooLike {
readonly foo: string,
readonly baz?:string,
someclass: SomeClass,
}
如何删除所有方法、getter 和 setter?
我试过这个:
export type NonFunctionPropertyNames<T> = {
// tslint:disable-next-line:ban-types
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];
export type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
let z: NonFunctionProperties<Foo>
但这不会删除 setter/getter
解决方案
推荐阅读
- git - 来自 repo 源代码的 gitc 文件系统是什么?
- r - R:在哪里为一个简单的 Shiny Web 应用程序插入个性测验功能
- c# - 将自定义方法添加到控制台 - C#
- javascript - 在 React.js 中存储基于文本的长段落或标题
- java - Maven java junit 测试不会从 groovy spock 测试开始
- google-bigquery - 在 Google BigQuery 中查询 JSON 字符串
- php - Laravel:如何将 GET 数组传递给控制器?
- python - Numpy:如何使用填充选择围绕选定的数组?
- java - 如何使用 spring jdbctemplate 查询搜索 H2 CLOB 数据类型列
- qt - Qt 作为统一的 UI