- Learn React with TypeScript 3
- Carl Rippon
- 99字
- 2021-06-10 19:16:32
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:
- 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.
- 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.
推薦閱讀
- Web Scraping with Python
- Oracle 12c中文版數據庫管理、應用與開發實踐教程 (清華電腦學堂)
- Python高級機器學習
- Java程序設計與實踐教程(第2版)
- Python數據可視化之Matplotlib與Pyecharts實戰
- Flux Architecture
- Android底層接口與驅動開發技術詳解
- INSTANT Apache Hive Essentials How-to
- Java EE項目應用開發
- Clojure編程樂趣
- Learning iOS Penetration Testing
- 輕松學Scratch 3.0 少兒編程(全彩)
- Eclipse開發(學習筆記)
- Python數據分析與挖掘實戰(第2版)
- Node.js核心技術教程