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

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.

主站蜘蛛池模板: 昌宁县| 黄山市| 新乡县| 油尖旺区| 定襄县| 五寨县| 毕节市| 当涂县| 丰台区| 丹巴县| 甘德县| 兴山县| 舒城县| 阿瓦提县| 望城县| 凤山市| 深圳市| 伊金霍洛旗| 沧源| 邓州市| 惠水县| 辽阳县| 华坪县| 贞丰县| 大埔区| 张北县| 南京市| 丘北县| 东明县| 潼关县| 阿拉善盟| 万安县| 隆安县| 洛南县| 尼勒克县| 柞水县| 肃南| 尖扎县| 兴隆县| 宁蒗| 达孜县|