15 个高级 TypeScript 开发技巧

1.可选链接(?.):
可选链接允许您安全地访问嵌套属性或方法,而不必担心 null 或未定义的值。如果任何中间属性为空或未定义,它会短路评估。

const user = {
   
    
    
  name: 'John',
  address: {
   
    
    
    city: 'New York',
    postalCode: '12345'
  

猜你喜欢

转载自blog.csdn.net/qq_52010446/article/details/131729107
今日推荐