flow:使用ExtractReturn的函数类型

时间:2017-11-07 10:05:54

标签: redux flowtype boilerplate

我正在尝试减少使用redux键入的flow代码的样板。

特别是,我希望避免手动定义action types,但让flow使用typed action creators技巧从ExtractReturn中推断出它们(如type _ExtractReturn<B, F: (...args: any[]) => B> = B; type ExtractReturn<F> = _ExtractReturn<*, F>; 中所述3}}或Shane Osbourne post):

action.id

但它没有发现简单错误,例如它应该发现numberstring而不是reducerMartin Hochel post

如果操作是“手动”定义的,则会收到错误:Try Flow

如何在Shane Osbourne post函数中正确捕获所有错误,而无需手动编写样板代码?

  • 修改:修正了试用流程链接。
  • 修改:我没有注意到Flow Try提供的includeTeamDriveItems似乎有效。看着它。实际上,它也有同样的问题。试着在帖子上发表评论来发出信号。请参阅评论Try Flow

1 个答案:

答案 0 :(得分:0)

如果您有兴趣,我设法让Flow抓住您的示例没有捕获的错误。 Here is the code

毫无疑问,黑客。我从this Github issue得到了这个想法。

除此之外,我无法提供更多见解。我自己在寻找更好的解决方案。

编辑:在挖掘了更多内容之后,我发现exception org.apache.jasper.JasperException: javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) root cause javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838) org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:169) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) root cause javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421 jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467) jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:389) jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190) com.DetAnom.dboperation.MyOperations.ReadData(MyOperations.java:58) org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:133) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) root cause <eval>:2:2321421 java.lang.RuntimeException: Method code too large! jdk.nashorn.internal.runtime.ECMAException.create(ECMAException.java:113) jdk.nashorn.internal.scripts.Script$Recompilation$1174$2321360II$\^eval\_.PgQuery$invoke_ii(<eval>:2) jdk.nashorn.internal.scripts.Script$Recompilation$1172$3313153AI$\^eval\_.:scopeCall-2(<eval>) jdk.nashorn.internal.scripts.Script$Recompilation$1172$3313153AI$\^eval\_.PgQuery$asm$Oc(<eval>:13) jdk.nashorn.internal.scripts.Script$Recompilation$1159$3314970II$\^eval\_.PgQuery$asm$Pc(<eval>:13) jdk.nashorn.internal.scripts.Script$Recompilation$1158$2960989AI$\^eval\_.PgQuery$asm$Ah(<eval>:9) jdk.nashorn.internal.scripts.Script$Recompilation$1157$2972086II$\^eval\_.PgQuery$asm$ji(<eval>:9) jdk.nashorn.internal.scripts.Script$Recompilation$1156$3374026AAA$\^eval\_.PgQuery$asm$kl(<eval>:14) jdk.nashorn.internal.scripts.Script$Recompilation$1155$73AA$\^function\_.L:1$dynCall_iii_35(<function>:3) jdk.nashorn.internal.scripts.Script$Recompilation$1153$118A$\^function\_.L:1$raw_parse(<function>:7) jdk.nashorn.internal.scripts.Script$Recompilation$1148$419A$\^eval\_.PgQuery$parse(<eval>:2) jdk.nashorn.internal.scripts.Script$Recompilation$1147$850A$signature.signature_hash(file:/C:/Users/RIT/Desktop/post/web/js/signature.js:41) jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639) jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383) jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190) com.DetAnom.dboperation.MyOperations.ReadData(MyOperations.java:58) org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:133) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) 实用程序类型可以提供一些帮助:

$Call

在此之后,或许值得将type Action = | $Call<typeof get, number> | $Call<typeof del, number> | $Call<typeof set, number, string> 模式抽象为自己的参数类型。但是,我对此时流量的了解是有限的,所以我的一些尝试并没有取得丰硕成果。

Here is the full refactor