打字稿中的 never 和 void 有什么区别? [英] What is the difference between never and void in typescript?

查看:23
本文介绍了打字稿中的 never 和 void 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读this,但不清楚从不"和无效"之间的区别' 类型?

I have read this, but it is unclear what would be the difference between 'never' and 'void' type?

推荐答案

在命令式语言中,void 可以被认为是一种包含单个值的类型.此类语言不提供构造或使用此值的方法,但可以将 void 函数视为返回此微不足道的值.

In imperative languages, void can be thought of as a type containing a single value. Such languages do not provide a means to construct or consume this value, but a void function can be thought of as returning this trivial value.

相比之下,never 是一种不包含值的类型,这意味着具有此返回类型的函数根本无法正常返回.这意味着要么抛出异常,要么无法终止.

In contrast never is a type containing no values, which means that a function with this return type can never return normally at all. This means either throwing an exception or failing to terminate.

这篇关于打字稿中的 never 和 void 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆