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

Void

void is another type that doesn't exist in JavaScript. It is generally used to represent a non-returning function.

Let's look at an example:

  1. Let's enter the following function into the TypeScript playground:
function logText(text: string): void {
console.log(text);
}

The function simply logs some text into the console and doesn't return anything. So, we've marked the return type as void.

  1. If we remove the return type annotation and hover over the function name, logText, we'll see that TypeScript has inferred the type to be void:

This saves us a few keystrokes while writing functions that don't return anything.

主站蜘蛛池模板: 灵武市| 赤壁市| 彝良县| 长海县| 淄博市| 蓝山县| 西宁市| 社会| 南通市| 松滋市| 湖南省| 商洛市| 林州市| 崇义县| 漳州市| 靖边县| 儋州市| 阜阳市| 鲁甸县| 祁连县| 鞍山市| 古丈县| 铁岭市| 云和县| 兴安盟| 宁阳县| 乐安县| 璧山县| 卓尼县| 中牟县| 天柱县| 衡阳县| 漳州市| 资源县| 崇仁县| 抚顺市| 宁乡县| 衡阳市| 宜州市| 淄博市| 漠河县|