当前位置:网站首页>[typescript] the difference between exclamation mark and question mark in typescript

[typescript] the difference between exclamation mark and question mark in typescript

2022-06-22 00:16:00 Silent tubule

// Because of the interface B Inside name Defined as nullable value , But the actual situation is not empty ,
// Then we can pass on class It uses !, Re emphasize name This is not null
!: Said no name Initial value

class A implemented B {
    
  name!: string
}

?: Express name Is an optional parameter , It means dispensable

interface B {
    
  name?: string
}
原网站

版权声明
本文为[Silent tubule]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206212226029621.html