- 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.
推薦閱讀
- Web安全防護指南:基礎(chǔ)篇
- CorelDRAW X6 中文版圖形設(shè)計實戰(zhàn)從入門到精通
- 物聯(lián)網(wǎng)(IoT)基礎(chǔ):網(wǎng)絡(luò)技術(shù)+協(xié)議+用例
- 異構(gòu)基因共表達網(wǎng)絡(luò)的分析方法
- WordPress 5 Complete
- Spring Cloud微服務(wù)架構(gòu)進階
- 局域網(wǎng)組建、管理與維護項目教程(Windows Server 2003)
- Learning Swift(Second Edition)
- Unity Artificial Intelligence Programming
- 從實踐中學(xué)習(xí)手機抓包與數(shù)據(jù)分析
- 深入理解Nginx:模塊開發(fā)與架構(gòu)解析
- 網(wǎng)絡(luò)空間全球治理觀察
- LwIP應(yīng)用開發(fā)實戰(zhàn)指南:基于STM32
- Cisco無線局域網(wǎng)配置基礎(chǔ)
- Hands-On Cloud:Native Microservices with Jakarta EE