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
{{ message }}
Repository navigation
Typescript act() got warning 'await' has no effect on the type of this expression.聽#1276
Looking at @types/react-test-render theirs act has following type:
export function act(callback: () => Promise<VoidOrUndefinedOnly>): Promise<undefined>;
As far as I understand the intention of async act is to allow for waiting for Promise returned by callback to resolve, but not to use it's return value in any way. We could actually tweak our typings to match @types/react-test-render ones.
/** * Simply calls ReactDOMTestUtils.act(cb) * If that's not available (older version of react) then it * simply calls the given callback immediately */exportconstact: typeofreactActextendsundefined
? (callback: ()=>void)=>void
: typeofreactAct
@qaynam Would such solution satisfy your use case?
Activity
mdjastrzebski commentedon Jan 7, 2023
Looking at
@types/react-test-rendertheirsacthas following type:As far as I understand the intention of async
actis to allow for waiting forPromisereturned bycallbackto resolve, but not to use it's return value in any way. We could actually tweak our typings to match@types/react-test-renderones.RTL does hits in the following way:
@qaynam Would such solution satisfy your use case?
trajano commentedon Jan 17, 2023
I'm not sure how you'd declare it in the act.ts file but the generated act.d.ts file should have these two lines
You have to also ensure that the linters will allow
Since these are valid cases where the useEffect performs an
asyncoperation that needs to be waited on.trajano commentedon Jan 20, 2023
I referenced this bug in https://stackoverflow.com/questions/64848604/how-to-resolve-act-in-useeffect/71949404#71949404 for more complete examples