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
The following is not working. Typescript cannot deduce the actual type of the handler. Listing 1:
functionmain1(props: PropTypes){Object.keys(props).forEach((key: keyofPropTypes)=>{map[key].handle(props[key]);// <-- Cannot invoke an expression whose type lacks a call signature... });}main1({'prop1': 42,'prop2': 'Hello World'})
The followings works. Listing 2:
functionmain2(props: PropTypes){Object.keys(props).forEach((key: keyofPropTypes)=>{lethandler=map[key]asHandler<{}>// <-- Works fine using a "cast"handler.handle(props[key]);});}main2({'prop1': 42,'prop2': 'Hello World'})
Listing 3:
functionmain3(props: PropTypes){Object.keys(props).forEach((key: keyofPropTypes)=>{helper(map[key],props[key]);// <-- Works fine using a "helper"});}functionhelper<KextendskeyofPropTypes>(handler: Handler<PropTypes[K]>,value: PropTypes[K]){handler.handle(value);}main3({'prop1': 42,'prop2': 'Hello World'})
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.5.3, 2.6.0rc
Please consider the following simple type definitions.
The following is not working. Typescript cannot deduce the actual type of the handler.
Listing 1:
The followings works.
Listing 2:
Listing 3:
Expected behavior:
Code in Listing 1 should compile without error
Actual behavior:
link to playground
The text was updated successfully, but these errors were encountered: