官术网_书友最值得收藏!

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):

  1. 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.

  1. Go back to your Terminal and compile and run this piece of code; type the following command:
tsc any.ts
  1. 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.

主站蜘蛛池模板: 衡阳县| 苗栗市| 遂平县| 黄龙县| 彭阳县| 策勒县| 霍山县| 上蔡县| 遵义市| 宜兰县| 锦州市| 龙泉市| 玉环县| 保康县| 浏阳市| 扎囊县| 社会| 马鞍山市| 越西县| 麻栗坡县| 芜湖市| 濮阳市| 宜宾市| 重庆市| 疏勒县| 自贡市| 红河县| 白河县| 郧西县| 嘉黎县| 博兴县| 玉屏| 剑阁县| 泸水县| 平原县| 台东县| 岑溪市| 棋牌| 湖北省| 沿河| 墨竹工卡县|