I have simple component that uses mobx and decorators like this
import * as React from "react";
import { observer, inject } from "mobx-react/native";
import { Router as ReactRouter, Switch, Route } from "react-router-native";
import Dashboard from "./_dashboard";
import { RouterInterface } from "../store/_router";
// -- types ----------------------------------------------------------------- //
export interface Props {
router: RouterInterface;
}
@inject("router")
@observer
class Router extends React.Component<Props, {}> {
// -- render -------------------------------------------------------------- //
render() {
const { router } = this.props;
return (
<ReactRouter history={router.history}>
<Switch location={router.location}>
<Route path="/" component={Dashboard} />
</Switch>
</ReactRouter>
);
}
}
export default Router;
essentially @inject("router") adds this.props.router that satisfies Props interface above, however typescript doesn't account for this and whenever I use this component somewhere I get an error if I don't pass down router in props, hence I need to change to router?: RouterInterface; which is fine, but not ideal.
Is there a way to fix this issue where typescript accounts for decorators injecting the props?