I would like to wrap the following function in mobx's observer()
, but can't seem to figure out how to do that (or if it's possible) while maintaining the generic typing:
interface GenericProps<T> {
arg: T;
}
const foo: <T>(props: GenericProps<T>) => T = (props) => props.arg;
This is a global exported function, so using the @observer
decorator is not an option (I think), I need to use the observer()
function from mobx-lite-react.
What I want is something like
interface GenericProps<T> {
arg: T;
}
const foo = observer<T>((props: GenericProps<T>) => props.arg);
Probably related to https://github.com/mobxjs/mobx-react-lite/issues/243, but from the conversation it is not clear to me how I would go about implementing the generic observer in my case.
React.FunctionComponent
interfaceextends unknown
which tells compiler this is generic definition and not JSX tag, return type doesn't need to be specified since it will be inferred)