【发布时间】:2022-06-14 21:58:18
【问题描述】:
在学习 NestJS 教程后,我遇到了一些引起我注意的事情(来自 service.ts 文件):
public async putCarById(id: number, property_name: string, property_value: string)// : Promise<any>
{
console.log(id); // gives provided number, for example, 1
const carId = Number(id);
console.log(typeof (id)); // will output "string" - why ?
console.log(typeof (carId)); // will output "number" -- which I understand
(...)
我找不到为什么必须进行“强制转换”,而 id 应该作为数字接收。
【问题讨论】:
-
大概类型是谎言; 在运行时它得到一个字符串,所以参数应该反映这一点。
标签: java node.js typescript parameters nestjs