ts 提示在赋值前使用了变量 startTime 那我要判断startTime是否赋值怎么判断?-灵析社区

你没饰八

比如 let startTime: number 然后在循环中判断是否赋值 if (!startTime) { // 报:在赋值前使用了变量"startTime" startTime = xxx } else { xxx }

阅读量:234

点赞量:13

问AI
let startTime: number | undefined 知道了 显式指定类型包括undefined就行了