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

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.

主站蜘蛛池模板: 渭源县| 潼南县| 肇东市| 驻马店市| 休宁县| 青龙| 滕州市| 麟游县| 常山县| 彝良县| 新郑市| 青铜峡市| 蓝山县| 渭源县| 五台县| 定南县| 连平县| 多伦县| 海宁市| 莲花县| 什邡市| 苍溪县| 石景山区| 修水县| 新泰市| 浙江省| 闵行区| 大庆市| 万荣县| 北碚区| 信丰县| 灵璧县| 武清区| 大渡口区| 巫山县| 鹤岗市| 赤水市| 临清市| 光泽县| 文化| 利川市|