- Learn React with TypeScript 3
- Carl Rippon
- 125字
- 2021-06-10 19:16:32
Any
What if we declare a variable with no type annotation and no value? What does TypeScript infer as the type? Let's enter the following code in the TypeScript playground and find out:
let flag;
If we hover our mouse over flag, we see it has been given the any type:
So, the TypeScript compiler gives a variable with no type annotation and no immediately assigned value, the any type. The any type is specific to TypeScript; it doesn't exist in JavaScript. It is a way of opting out of type checking on a particular variable. It is commonly used for dynamic content or values from third-party libraries. However, TypeScript's increasingly powerful type system means that we need to use any less often these days.
推薦閱讀
- ServiceNow Application Development
- The Android Game Developer's Handbook
- 程序員面試算法寶典
- Unity Virtual Reality Projects
- Learning Elixir
- 網(wǎng)站構(gòu)建技術(shù)
- C語言程序設(shè)計
- Haskell Data Analysis Cookbook
- Python機(jī)器學(xué)習(xí)之金融風(fēng)險管理
- Struts 2.x權(quán)威指南
- 程序員的成長課
- 游戲設(shè)計的底層邏輯
- 計算機(jī)系統(tǒng)解密:從理解計算機(jī)到編寫高效代碼
- Java服務(wù)端研發(fā)知識圖譜
- MATLAB計算機(jī)視覺實戰(zhàn)