使用类型断言将“string[]”类型转换为“string”。
代码示例:
// 原代码
let str: string | undefined = ["hello", "world"]; // 报错:Type 'string[] | undefined' is not assignable to type 'string | undefined'
// 解决方法
let str: string | undefined = (["hello", "world"] as string[])[0]; // 使用类型断言将数组类型转换为字符串类型