Introducing an interface designed to accept two templates, with the resulting function being a partial of one of them (similar to React-Redux):
export type IState<TState, TOwnProps> = {
connect: (mapStateToProps: MapStateToProps<TState, Partial<TOwnProps>>) => () => any;
}
export type MapStateToProps<TState, TStateProps> = (state: TState) => TStateProps;
Let's explore an example state that can make use of this interface:
interface IAppState {
services: string[]
}
interface IAppProps {
services: string[];
count: number;
}
const MyState: IState<IAppState, IAppProps>;
MyState.connect(
(state) => {
return {
services: state.services,
foo: null
}
}
);
The MyState.connect
method should receive a single function as its argument, which it does. The argument should be of type
IAppState</code, which is also correct. However, the expected return type is a <code>Partial<IAppProps>
. Despite returning foo: null
in addition to services, there are no errors raised.
Where could my mistake be in this scenario?