Ts常见Error

322 阅读1分钟

TS2532: Object is possibly 'undefined'

错误解析:对象可能是未定义的

image.png

image.png

使用可选链(?.) 解决 (或者使用if判断都可以的)

state.tableData.search.data[0].options?.push({
    label: item.sname,
    value: item.iid
  })

Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'

image.png

  • 查找得知 image.png
  • 解决
export type {CustomerType}

TS2339: Property 'iid' does not exist on type 'object'.

当子组件props接收父组件传递过来的一个object对象数据时,直接写 props.obj.iid,就会报上面的错误提示

  • objectJavaScript 中的一种通用类型,它可以表示任何对象。因此,在 props.elderlyInformation 上访问属性 iid 会报提示,因为他也不知道有没有,定义一个接口直接指定类型即可。

image.png

image.png