繁体   English   中英

你能创建一个 ts 定义来检查任何打字稿接口吗?

[英]can you create a ts definition that checks for ANY typescript interface?

我有一个接口,我想在我的定义中强制定义一个接口,但允许使用任何接口。 就像是...

interface Foo {
  enabled: boolean
}

interface Settings {
  [key: string]: AnyInterface

  // will pass
  foo: IFoo;

  // will fail
  bar: {
    key: string;
  }
}

我想避免[key: string]: IFoo | IBar | ... [key: string]: IFoo | IBar | ... [key: string]: IFoo | IBar | ... 这可能吗? 或者可能是一个更好的解决方案?

暂无
暂无

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

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