250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- nextJS
- 삶
- API
- Redux
- solidity
- typeScript
- JavaScript
- concept
- useState
- error
- REACT
- HTML
- express.js
- CLASS
- 기준
- hardhat
- bitcoin
- tailwindcss
- built in object
- blockchain
- node.js
- Ethereum
- middleware
- SSR
- web
- evm
- Interface
- CSS
- graphQL
- Props
Archives
- Today
- Total
ReasonJun
Typescript : additional provided types (void, never) 본문
Frontend/Typescript
Typescript : additional provided types (void, never)
ReasonJun 2023. 6. 17. 15:33728x90
The void type is used to represent functions that do not return a value. This is typically used for functions that have side effects, such as logging or printing to the console. For example:
function logMessage(message: string): void {
console.log(message);
}
const result = logMessage("Hello, world!"); // The result of this function is void
The never type is used to represent functions that never return a value. This is typically used for functions that always throw an error or enter an infinite loop. For example:
function throwError(): never {
throw new Error("This function always throws an error");
}
const result = throwError(); // The result of this function is never
The main difference between void and never is that void allows functions to return undefined, while never does not. This is because undefined is a valid value in JavaScript, while never is not.
Here is a table that summarizes the key differences between void and never:
728x90
'Frontend > Typescript' 카테고리의 다른 글
What is "not assignable to parameter of type never" error in TypeScript? (0) | 2023.07.12 |
---|---|
Typescript : When I use 'type annotation', 'type inference', 'type assertion' in typescript (0) | 2023.06.17 |
Typescript : additional provided types (Enum) (0) | 2023.06.17 |
Typescript : tsconfig.json (0) | 2023.06.10 |
Typescript : Module (CommonJS / ECMAScript Modules) (0) | 2023.06.10 |
Comments