Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 使用父类';Typescript中的s方法类型_Class_Typescript_Inheritance - Fatal编程技术网

Class 使用父类';Typescript中的s方法类型

Class 使用父类';Typescript中的s方法类型,class,typescript,inheritance,Class,Typescript,Inheritance,我注意到当你扩展一个类的时候,这些类型并没有通过,我想知道是否有一种方法可以在类型定义中实现这一点?以下是一些psuedo代码: class A { render(props: Object) { } } class B extends A { render(props) { <- right now its an any type, I'd like it to inherit from A } } 干杯 您必须重新定义该方法的类型。但是,如果您定义了一个比基类

我注意到当你扩展一个类的时候,这些类型并没有通过,我想知道是否有一种方法可以在类型定义中实现这一点?以下是一些psuedo代码:

class A {
  render(props: Object) {

  }
}

class B extends A {
  render(props) { <- right now its an any type, I'd like it to inherit from A

  } 
}

干杯

您必须重新定义该方法的类型。但是,如果您定义了一个比基类宽松的类,您将得到一个错误

这项工作:

A类{
渲染(道具:字符串){
}
}
B类扩展了A类{
渲染(道具:字符串){
} 
}
这并不是:

A类{
渲染(道具:字符串){
}
}
B类扩展了A类{
渲染(道具:数字){
} 
}

您必须重新定义该方法的类型。但是,如果您定义了一个比基类宽松的类,您将得到一个错误

这项工作:

A类{
渲染(道具:字符串){
}
}
B类扩展了A类{
渲染(道具:字符串){
} 
}
这并不是:

A类{
渲染(道具:字符串){
}
}
B类扩展了A类{
渲染(道具:数字){
} 
}

另请查看此答案是否是您一直在寻找的答案,请将其标记为正确答案,以便其他人也知道。:)如果这个答案是您一直在寻找的,请将其标记为正确答案,这样其他人也会知道。:)
class A {
  render(props: Object) {

  }
}

class B extends A {
  render(props: this.props) {

  } 
}