typescript指定参数-Typescript 函数参数指定数字但接收字符串

我正在尝试调用 Angular 9 中的服务函数,将文本数组中的输入从摄氏温度转换为开尔文温度。 我指定了一个以摄氏度为单位的函数,通过添加 273.15 来估计开尔文。 相反,它在后端连接起来。 我测试了代码typescript指定参数,果然它在接受字符串作为数字后返回了字符串。 转换号码可以解决问题typescript指定参数,但有人可以帮助我理解为什么打字不会导致呼叫失败,或者至少会立即将其丢弃吗?

    public convertCToK(celsius: number): number { // e.g. celsius = 1
        console.log(typeof celsius); // returns 'string'
        // return celsius + 273.15; returns 1273.15
        return Number(celsius) + 273.15; // returns 274.15
    }

调用函数和 HTML

    fahrenheit: number;
    celsius: number;
    kelvin: number;
    changeC() {
      if (!isNaN(this.celsius)) {
        this.fahrenheit = Math.round(this.calcService.convertCToF(this.celsius) * 100) / 100;
        this.kelvin = Math.round(this.calcService.convertCToK(this.celsius) * 100) / 100;
      }
    }

    

Fahrenheit:


Celsius:


Kelvin: