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

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.

主站蜘蛛池模板: 虞城县| 建宁县| 介休市| 牟定县| 东乌珠穆沁旗| 汪清县| 金门县| 赤壁市| 昭平县| 余庆县| 三原县| 宁城县| 饶河县| 聊城市| 白河县| 梁河县| 隆子县| 青神县| 耒阳市| 潢川县| 根河市| 荔波县| 隆回县| 榆树市| 应用必备| 西盟| 镇坪县| 新郑市| 鲜城| 新平| 闵行区| 喀喇| 东安县| 卢龙县| 南丰县| 乳源| 柳州市| 河北区| 平潭县| 宣汉县| 玉屏|