- 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.
推薦閱讀
- C#高級(jí)編程(第10版) C# 6 & .NET Core 1.0 (.NET開發(fā)經(jīng)典名著)
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開發(fā)入門與實(shí)戰(zhàn)(跨平臺(tái)移動(dòng)開發(fā)叢書)
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- 算法精粹:經(jīng)典計(jì)算機(jī)科學(xué)問題的Java實(shí)現(xiàn)
- Python進(jìn)階編程:編寫更高效、優(yōu)雅的Python代碼
- Expert Android Programming
- 零基礎(chǔ)學(xué)Python數(shù)據(jù)分析(升級(jí)版)
- Apache Spark 2.x for Java Developers
- Java網(wǎng)絡(luò)編程實(shí)戰(zhàn)
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)訓(xùn)教程
- Learning D
- Python物理建模初學(xué)者指南(第2版)
- C語言程序設(shè)計(jì)與應(yīng)用實(shí)驗(yàn)指導(dǎo)書(第2版)
- Mastering Magento Theme Design
- Learning PrimeFaces Extensions Development