M
M
MaximPatrushev2019-09-21 10:52:36
typescript
MaximPatrushev, 2019-09-21 10:52:36

What is the correct way to use typescript(interfaces) with MobX?

There are 2 components, parent and child.
The child is connected to the mobx store.

interface IProps {
  exercisesStore: {
    isExercisesLoading: boolean;
    exercises: IExercise[];
    addExercise: (exercise: IExercise) => void;
    updateExercise: (exercise: IExercise) => void;
  };  
}

const ChildComponent: FC<IProps> = inject('exercisesStore')(
  observer(({ exercisesStore }) => {  
 // ...
}));
export default ChildComponent;

When I use it like this in the parent, tslint shows me an error, they say
const ParentComponent: FC = ( ) => {  
   // ...
  <ChildComponent />
}
export default ParentComponent;

5d85d67802df0124378663.png
The question is - am I somehow using interfaces with MobX incorrectly or is the tslint configured incorrectly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaximPatrushev, 2019-09-22
@MaximPatrushev

The issue is resolved, one of the workarounds should be written like this:

exercisesStore?: {
    ...
  };

And then in the code, use the store with this syntax, telling the TC that there is definitely a store:
... exercisesStore!.exercises ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question