ALL
The Strange Behavior of the void Type in TypeScript
PrefaceIn TypeScript (TS), there is a type called void. It represents "nothing" but it's important to note that it's not the same as "nothing" in JavaScript(JS).Typically, void is used to declare the return type of functions. Although you can declare a variable as void, we generally don't do this because it serves no meaningful purpose. Let's explore why in the examples below.The void TypeDeclaring a Variable as voidlet name: void; // Declare a variable `name` with type `void`.name = 'nanjiu'; // Error: Cannot assign type 'string' to type 'void'.name = 18; // Error: Cannot assign type 'number'...
5,563 1 JAVASCRIPT TYPE TYPESCRIPT VOID