You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importexpress= require("express");constapp=express();constmethod=(someCondition()) ? "get" : "post";// method is "get" or "post"app[method](reqHandler);
Expected behavior:
Ideally, app[method] could be inferred as typeof app.get | typeof app.post
Actual behavior: app[method] gives an implicit any error, since app doesn't have an index signature. Doing (<any>app)[method] removes the error, but leaves app[method] as type any rather than typeof app.post | typeof app.get.
To get proper typing, I can do: (<typeof app.get | typeof app.post>(<any>app)[method]), but that's super ugly.
TypeScript Version: 2.1.0-dev.dev.20160920
Code
Expected behavior:
Ideally,
app[method]
could be inferred astypeof app.get | typeof app.post
Actual behavior:
app[method]
gives an implicit any error, since app doesn't have an index signature. Doing(<any>app)[method]
removes the error, but leavesapp[method]
as type any rather thantypeof app.post | typeof app.get
.To get proper typing, I can do:
(<typeof app.get | typeof app.post>(<any>app)[method])
, but that's super ugly.The below almost works:
except that
.bind()
calls returnany
.The text was updated successfully, but these errors were encountered: