interface Iparent {
a: string
}
interface Ichild extends parent {
a: '';
}
const x: child = {}这抛出了一个编译器错误,当使用子接口时,如何为子接口中的a提供默认值?
编辑:
Class parent实际上看起来像这样:
class parent extends React.Component<Iparent> {}
class child extends React.Component<Ichild> {}父类应该有一个属性,而子类应该只有一个默认值,即'‘
发布于 2020-12-13 03:43:42
这里有几个错误:
a: '' value.'',就像animal: 'dog' | 'cat'可以是'dog',也可以是'cat',没有默认值-它们的使用方式类似于较少指定的类型。如果你想要有缺省值,你应该使用类:
class child implements parent{
a = '';
}
const x: child = new child();https://stackoverflow.com/questions/65269046
复制相似问题