Yan*_*hon 2 typescript typescript-typings
在寻找修复d.ts文件中错误的方法时,我需要从基类型中省略一些方法,因为我正在处理的自定义类重新定义了它们。
我找到了Omit辅助类型,它在这样的示例中使用:
type Foo = {
a() : void;
b() : void;
c() : void;
toString() : string;
};
type BaseFoo = Omit<Foo, "a">;
Run Code Online (Sandbox Code Playgroud)
但是,如果我需要同时删除a、b和cin该怎么办BaseFoo?
看来我可以做
type BaseFoo = Omit<Omit<Omit<Foo, "a">, "b">, "c">;
Run Code Online (Sandbox Code Playgroud)
但有没有更干净的方法来做到这一点?
是的,使用联合:
type BaseFoo = Omit<Foo, 'a'|'b'|'c'>;
Run Code Online (Sandbox Code Playgroud)
或者只是使用Pick<Foo,'toString'>
| 归档时间: |
|
| 查看次数: |
986 次 |
| 最近记录: |