【发布时间】:2019-02-21 16:44:33
【问题描述】:
我在 typescript 中定义了以下数组:let ids: string[] = [];。然后,当我尝试推送一个 id(可能未定义)时,我遇到了编译错误:ids.push(id); 给了我以下编译错误:
TS2345:类型参数“字符串”| undefined' 不能分配给“字符串”类型的参数。类型“未定义”不可分配给类型“字符串”。
我可以创建字符串数组和未定义的数组吗?
【问题讨论】:
-
let ids: (string | undefined)[] = []; -
你的 tsconfig 是什么样的?
标签: typescript