score:5

i was able to do this in ts 2.3. the point is to use 2 types for "inside" and "outside" of that component.

interface iprops<v> {
    value: v;
    dosomething(val: v): void;
}

// type "inside" component
function _comp<t>(props: iprops<t>) {
    return <div />;
}

// type for "outside" of component
interface genericssfc extends react.sfc<any> {
    <t>(props: iprops<t> & { children?: react.reactnode }, context?: any): jsx.element;
}

const comp = _comp as genericssfc;

// dont type check: v is of type "hey"
<comp value={"hey"} dosomething={v => v - 1} />;

Related Query

More Query from same tag