Я хочу получить компонент с его типами реквизита, но Typescript не может вывести их, если я верну компонент из вложенной функции.
Я попытался вернуть компонент из неопубликованной функции,работает, но не из вложенного
Я ожидаю получить ComponentType<ICompProps>
от getComponentFromNestedFunction
нажмите следующую ссылку, чтобы увидеть полностью: пример кода
interface ICompProps {
pass?: string;
user?: string;
}
function getComponentFromNestedFunction<Props>(
func: () => void
): (Comp: ComponentType<Props>) => ComponentType<Props> {
return Comp => Comp;
}
function getComponent<Props>(
Comp: ComponentType<Props>
): ComponentType<Props> {
return Comp;
}
const Comp: ComponentType<ICompProps> = p => {
return <div>{p.user}</div>;
};
// How can I change the code so I can get the prop types like in ComponentWithPropTypes?
const ComponentWithoutPropTypes = getComponentFromNestedFunction(() => ({
user: "user"
}))(Comp);
// hover (in a code editor) ComponentWithPropTypes and see the prop types: const ComponentWithPropTypes: React.ComponentType<ICompProps>
const ComponentWithPropTypes = getComponent(Comp);
}