相关疑难解决方法(0)

如何在TypeScript中通过映射类型删除属性

这是代码

class A {
    x = 0;
    y = 0;
    visible = false;
    render() {

    }
}

type RemoveProperties<T> = {
    readonly [P in keyof T]: T[P] extends Function ? T[P] : never//;
};


var a = new A() as RemoveProperties<A>
a.visible // never
a.render() // ok!
Run Code Online (Sandbox Code Playgroud)

我想通过RemoveProperties删除"visible/x/y"属性,但我只能用never替换它

typescript typescript-typings mapped-types

9
推荐指数
2
解决办法
2348
查看次数