- 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.
推薦閱讀
- Mastering Concurrency Programming with Java 8
- Spring 5.0 By Example
- 零基礎搭建量化投資系統:以Python為工具
- Angular UI Development with PrimeNG
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- Full-Stack Vue.js 2 and Laravel 5
- SQL Server 2008 R2數據庫技術及應用(第3版)
- JSP程序設計實例教程(第2版)
- 智能手機故障檢測與維修從入門到精通
- ASP.NET 4.0 Web程序設計
- Moodle 3 Administration(Third Edition)
- The Statistics and Calculus with Python Workshop
- PHP程序設計高級教程
- Python3從入門到實戰
- 數據庫基礎與應用實驗教程:Visual FoxPro 6.0