How do you detect NgRx createAction duplicate types

不羁岁月 提交于 2020-03-03 10:19:46

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/59437827/how-do-you-detect-ngrx-createaction-duplicate-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!