- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 148字
- 2021-07-23 19:18:50
The opt-out type checking - any
The any type is very useful when we do not know what to expect from a function (in other words, when we do not know which type we are going to return):
- Create a new file called any.ts inside the chapter-02 folder, and add the following code:
let band: any;
band = {
name: "Motorhead",
description: "Heavy metal band",
rate: 10
}
console.log(band);
band = "Motorhead";
console.log(band);
Note that the first band assignment is an object, while the second is a string.
- Go back to your Terminal and compile and run this piece of code; type the following command:
tsc any.ts
- Now, let's see the output. Type the following command:
node any.js
You will see the following message in the Terminal:
{ name: 'Motorhead', description: 'Heavy metal band', rate: 10 }
Motorhead
Here, we can assign anything to our band variable.
推薦閱讀
- 智慧城市:大數據、互聯網時代的城市治理(第4版)
- 網絡協議工程
- 物聯網網絡安全及應用
- 物聯網檢驗檢測技術
- TCP/IP入門經典(第5版)
- Getting Started with WebRTC
- 通信簡史:從信鴿到6G+
- 物聯網安全技術
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 計算機網絡工程實用教程(第2版)
- WordPress Web Application Development
- 6G新技術 新網絡 新通信
- Practical Web Penetration Testing
- Hands-On Microservices with Node.js
- Learning Node.js Development