打字稿定义,此以及对继承的误解

时间:2019-03-11 18:51:55

标签: typescript typescript-typings

我正在创建一个定义以表示npm(gui)上的现有软件包。

我需要实现以下内容:

//now i want the label in this method to be displayed when a button is clicked in the second form

public void display()
{
    cityVar = cities;
    dateVar = Date;
    min_TempVar = MinTemp; 
    maxTempVar = MaxTemp;
    precipitationVar = precipitation;
    humidityVar = humidity;
    windSpeedVar = Wind;

    // ReportForm rf = new ReportForm(); i am calling the second form
    // rf.Display_Label.Text  is a label in the Report form 

    rf.Display_Label.Text = string.Format(@"
    Weather forecast for {0} 
    for the  {1}
    ------------------------------------------
    min temp: {2} C
    max temp: {3} C
    precipitation: {4} %
    humidity: {5} % 
    wind speed:{6} km/h ",
    cityVar, dateVar, min_TempVar, maxTempVar, precipitationVar, 
    humidityVar,windSpeedVar);

}

//this how i did it but it does not seem to work , can someone please assist me in the correct way to do this
private void button1_Click(object sender, EventArgs e)
{
    //  WeatherApp form = new WeatherApp(); calls the first form
    WeatherApp form = new WeatherApp();
    // form.display() should call the Public void display method which is in the WeatherApp form 
    form.display(); 
}

我遇到以下问题:

class A {
    onEventA: (self: this) => void;
    static create(): A;
}

class B extends A {
    onEventB: (self: this) => void;
    static create(): B;
}

现在,如果我将其更改为:

TS2417: Class static side of 'typeof B' incorrectly extends base class static side 'typeof A'.
  Types of property 'create' are incompatible.
    Type '() => B' is not assignable to type '() => A'.
      Type 'B' is not assignable to type 'A'.
        Types of property 'onEventA' are incompatible.    
          Type '(self: B) => void' is not assignable to type '(self: A) => void'.
            Types of parameters 'self' and 'self' are incompatible.
              Property 'onEventB' is missing in type 'A' but required in type 'B'

错误消失了。

为什么将它们定义为方法有效,而将其定义为属性却失败了?

0 个答案:

没有答案