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
TypeScript Version: 3.8.3 (also tested with 3.9.0-dev.20200425)
Search Terms:
inference
Code
typeEffect<T,M>={// NOTE: The problem seems to be here somewhere. Getting rid of the// intersection `& M` below gets rid of the error.do?: (o: T&M)=>void;};typeObj={};functioncreate<T,M>(params: {methods: M;effect: Effect<T,M>;}): Obj&M{returnparams.methods}constobj=create({// If the parameter below is inferred then the Obj type// breaks and the methods are no longer merged in.// If a type is given (e.g. `obj:any`) the methods work// as expectedeffect:{do: (obj)=>{}},methods: {something(){}}});// This will be an error if the effect infers the parameter typeobj.something();
Expected behavior:
Functions in methods should be merged into the type that is output by create or an error should be generated if there is a problem with the types.
Actual behavior:
Function in methods are only merged if do in effects is defined with explicitly typed parameters and no error is generated.
The problem here is that you have no inference site for T, so T gets fixed to unknown, then this ends up with M getting unknown because of inference on the obj parameter. The straightforward fix is to just remove T from these declarations entirely. A more fleshed-out example might be something we could provide a better way to write a declaration for
TypeScript Version: 3.8.3 (also tested with 3.9.0-dev.20200425)
Search Terms:
inference
Code
Expected behavior:
Functions in
methods
should be merged into the type that is output bycreate
or an error should be generated if there is a problem with the types.Actual behavior:
Function in
methods
are only merged ifdo
ineffects
is defined with explicitly typed parameters and no error is generated.Playground Link: playground
The text was updated successfully, but these errors were encountered: