書名: Learn React with TypeScript 3作者名: Carl Rippon本章字數(shù): 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.
推薦閱讀
- 程序員面試白皮書
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- HBase從入門到實戰(zhàn)
- 實戰(zhàn)Java程序設(shè)計
- Mastering Android Development with Kotlin
- C#開發(fā)案例精粹
- Julia數(shù)據(jù)科學應(yīng)用
- Unity Android Game Development by Example Beginner's Guide
- Clojure High Performance Programming(Second Edition)
- Mastering OpenStack
- Java EE輕量級解決方案:S2SH
- 一步一步學Spring Boot:微服務(wù)項目實戰(zhàn)(第2版)
- 創(chuàng)新工場講AI課:從知識到實踐
- Getting Started with the Lazarus IDE
- Java Web入門很輕松(微課超值版)