简体   繁体   English

如何扩展TypeScript接口并对其进行局部处理

[英]How to extend a TypeScript interface and unpartial it

I want to be able to do the following: 我希望能够执行以下操作:

interface Partials {
  readonly start?: number;
  readonly end?: number;
}

interface NotPartials extends Partials /*incorporate Unpartialing somehow */ {
  readonly somewhere: number;
}

Then, NotPartials would be: 然后,NotPartials将是:

readonly start: number;
readonly end: number;
readonly somewhere: number;

Notice how start and end are required now. 注意现在如何开始和结束。 Is this possible anyway? 反正有可能吗?

Well, this is silly. 好吧,这很愚蠢。

I think in TypeScript 2.8 this is possible: 我认为在TypeScript 2.8中这是可能的:

interface Partials {
  readonly start?: number;
  readonly end?: number;
}

interface NotPartials extends Required<Partials> {
  readonly somewhere: number;
}

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

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