我可以在 TypeScript 中将函数限制为纯函数吗? [英] Can I restrict a function to be pure in TypeScript?

查看:32
本文介绍了我可以在 TypeScript 中将函数限制为纯函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让函数成为 pure (因此不接受 TypeScript 中的非纯函数?如果是,是哪个?

Is there a way to allow a function to be pure only (thus not accepting the function to be non pure) in TypeScript? If yes, which?

推荐答案

您可能能够编写一些 TSLint 规则来捕获大多数常见情况(例如,访问外部变量),但检查类似的内容是几乎不可能,所以没有办法真正 100% 知道.

You might be able to write a few TSLint rules to catch most of the common cases (access to outside variables, for example), but checking something like that is nigh impossible, so there's no way to actually know 100%.

您(和您的团队)仍然必须遵守纪律.

You (and your team) still have to be disciplined.

这篇关于我可以在 TypeScript 中将函数限制为纯函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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