- 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.
推薦閱讀
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- 微服務與事件驅動架構
- 營銷數據科學:用R和Python進行預測分析的建模技術
- VMware虛擬化技術
- Python機器學習基礎教程
- Mastering JavaScript Design Patterns(Second Edition)
- Mastering Android Development with Kotlin
- Node.js開發指南
- 時空數據建模及其應用
- Java EE Web應用開發基礎
- 邊玩邊學Scratch3.0少兒趣味編程
- UX Design for Mobile
- Getting Started with Electronic Projects
- Analytics for the Internet of Things(IoT)