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
action -wrapped function with implicit argument types can be assigned as an optional property of a object, and the types are correctly inferred.
import{action}from"mobx";// Both should be OKconsttes1: {a: (x: number)=>void;}={a: action((x)=>console.log(x.toFixed()))};consttest2: {a?: (x: number)=>void;}={a: action((x)=>console.log(x.toFixed()))};
Actual outcome:
Implicit argument types in action -wrapped function assigned as an optional property of a object becomes any and causes an error in struct environments.
import{action}from"mobx";// OKconsttes1: {a: (x: number)=>void;}={a: action((x)=>console.log(x.toFixed()))};// OK in MobX 5, Error in MobX 6 (x becomes any)consttest2: {a?: (x: number)=>void;}={a: action((x)=>console.log(x.toFixed()))// ↑ "Parameter 'x' implicitly has an 'any' type. ts(7006)" error in this line};
Looks like MobX 5 works fine because undefined is added to T in this line. Adding undefined to T in Mobx6 action.d.ts fixed the problem in my environment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Intended outcome:
action
-wrapped function with implicit argument types can be assigned as an optional property of a object, and the types are correctly inferred.Actual outcome:
Implicit argument types in
action
-wrapped function assigned as an optional property of a object becomesany
and causes an error in struct environments.Looks like MobX 5 works fine because
undefined
is added toT
in this line. Addingundefined
toT
in Mobx6action.d.ts
fixed the problem in my environment.How to reproduce the issue:
https://codesandbox.io/s/mobx-action-error-gnd8v
Versions
Occurs in MobX 6. MobX 5 works fine.
The text was updated successfully, but these errors were encountered: