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

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

问题描述

是否有一种方法可以仅将函数设为纯"(因此不接受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天全站免登陆