Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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
如何从javascript类继承typescript类_Javascript_Typescript - Fatal编程技术网

如何从javascript类继承typescript类

如何从javascript类继承typescript类,javascript,typescript,Javascript,Typescript,我使用Javascript模块为自定义扩展类扩展类 我用typescript编写了自定义类,但在消息下面遇到了一个错误 Property 'jsFunc' does not exist on type 'tsClass'.ts(2339) 我认为,因为Javascript类没有类型信息,所以它不能带来任何属性 如何正确处理这个问题 范例 book.js 教材{ 页 建造师(第页){ this.page=page; } 开(){ _next(); } _下一个(){ this.page=this

我使用Javascript模块为自定义扩展类扩展类

我用typescript编写了自定义类,但在消息下面遇到了一个错误

Property 'jsFunc' does not exist on type 'tsClass'.ts(2339)
我认为,因为Javascript类没有类型信息,所以它不能带来任何属性

如何正确处理这个问题

范例

book.js

教材{
页
建造师(第页){
this.page=page;
}
开(){
_next();
}
_下一个(){
this.page=this.page++;
}
}
漫画书

class commicbook扩展了书本{
page;//如果不是,则是不存在的错误
开(){
本页=10;
_next();//类型“commicbook.ts”上不存在属性“_next()”
}
}

要在当前类上调用方法,您需要在
前面加上以下内容:

this._next();

要在当前类上调用方法,您需要在
this
前面加上前缀:

this._next();

从javascript类继承typescript类的一种方法是:

class Person {
  firstName: string;
  lastName: string;
 
 constructor (fName: string, lName: string) {
      this.firstName = fName;
      this.lastName = lName;
 }
 
 getFullName() {
  return `${firstName} ${lastName}`;
 }
}
class Employee extends Person {
 empID: string;
 designation: string;

 constructor (fName: string, lName: string,
     eID: string, desig: string) {
  
  super(fName, lName);
  
  this.empID = eID;
  this.designation = desig;
 }
 
 toString() {
  return `${empID} - ${firstName} ${lastName}
    => ${designation}`;
 }
}

从javascript类继承typescript类的一种方法是:

class Person {
  firstName: string;
  lastName: string;
 
 constructor (fName: string, lName: string) {
      this.firstName = fName;
      this.lastName = lName;
 }
 
 getFullName() {
  return `${firstName} ${lastName}`;
 }
}
class Employee extends Person {
 empID: string;
 designation: string;

 constructor (fName: string, lName: string,
     eID: string, desig: string) {
  
  super(fName, lName);
  
  this.empID = eID;
  this.designation = desig;
 }
 
 toString() {
  return `${empID} - ${firstName} ${lastName}
    => ${designation}`;
 }
}