import * as PropTypes from "prop-types"; import * as React from "react"; import { State } from "@app/state"; interface IProvidedStateContext { providedState: State; } const providedStateContextTypes: PropTypes.ValidationMap = { providedState: PropTypes.object, }; export class ProvideState extends React.Component<{ state: State, }> implements React.ChildContextProvider { static childContextTypes = providedStateContextTypes; getChildContext(): IProvidedStateContext { return { providedState: this.props.state, }; } render() { return React.Children.only(this.props.children); } } type Diff = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; type Omit = {[P in Diff]: T[P]}; export function injectState

>(Component: T) { return class extends React.Component> { static contextTypes = providedStateContextTypes; context: IProvidedStateContext; render() { const state = this.context.providedState; return ; } }; }