我在代码中遇到打字错误typescript Property 'type' does not exist on type 'never'
export const getSomething = (actionLog: [] | undefined) => {
console.info(actionLog[length - 1].type)
}
出了什么问题?
答案 0 :(得分:0)
解决方案是为'type'属性定义类型:
export const getSomething = (actionLog: {type: string}[] | undefined) => {
console.info(actionLog[length - 1].type)
}
已更新:
export const getSomething = (actionLog: {type: string}[]) => {
if (actionLog && actionLog[0]) {
console.info(actionLog[length - 1].type)
}
}