如何检测NgRx createAction重复类型 [英] How do you detect NgRx createAction duplicate types

查看:59
本文介绍了如何检测NgRx createAction重复类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NgRx中使用复制和粘贴添加新动作时,有时可能会忘记更改为纯字符串的动作类型.当然,将其设置为静态static var可以使其可能性降低,但仍然可以实现.

When using copy and paste to add new actions in NgRx, it is sometimes possible to forget to change the action type that is a plain string. Sure, making it a static static var makes it less likely, but still possible.

您如何检测这种疏忽?它可能会导致怪异的错误,这些错误在运行时很难被跟踪,并且似乎在编译时更容易避免.

How do you detect this oversight? It can cause weird bugs that are hard to track down at runtime and seems to be something that is easier to avoid at compile time.

例如,这些将在运行时导致问题,在编译时没有任何警告

For example, these will cause an issue at runtime, without any warnings at compile time

export const meeting_user_doc = createAction(
  '[User] selected doc',
  props<{docGuid: string}>()
);

export const meeting_user_image = createAction(
  '[User] selected doc',
  props<{imageGuid: string}>()
);

如果工具在编译时照顾好它,那就太好了……但是,即使有一种方法可以在启动时对所有动作进行迭代并识别它们,也可以节省大量调试这些问题的时间.

It would be great if the tools take care of it at compile time... but even if there is a way to iterate over all the actions at startup and identify these, it would save a lot of time debugging these issues.

推荐答案

我的软件包[ngrx-tslint-rules( https://github.com/timdeschryver/ngrx-tslint-rules#readme )具有覆盖重复操作类型的规则-请参见

My package [ngrx-tslint-rules(https://github.com/timdeschryver/ngrx-tslint-rules#readme) has a rule to cover duplicate action types - see the example

这篇关于如何检测NgRx createAction重复类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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