TypeScript - 型別推論與聯合型別
型別推論 Type Inference
變數在宣告的時候如果沒有明確指定任何型別,TypeScript 就會依照型別推論(Type Inference)的規則來推測出變數的型別。
變數的型別推論
let something = 'Hello' // 等同於 let something: string = 'Hello'
something = 7
// index.ts: error TS2322: Type 'number' is not assignable to type 'string...
yachuh.hashnode.dev2 min read