使用可选属性扩展TypeScript类型

问题描述

我正在使用NextJS,需要使用我自己添加了AppProps的可选参数来扩展其Layout类型。但是AppProps类型由许多其他类型组成,例如

AppProps:

export declare type AppProps<P = {}> = AppPropsType<Router,P>;

AppPropsType:

export declare type AppPropsType<R extends NextRouter = NextRouter,P = {}> = AppInitialProps & {
    Component: NextComponentType<NextPageContext,any,P>;
    router: R;
    __N_SSG?: boolean;
    __N_SSP?: boolean;
};

NextComponentType:

export declare type NextComponentType<C extends BaseContext = NextPageContext,IP = {},P = {}> = ComponentType<P> & {
    /**
     * Used for initial page load data population. Data returned from `getInitialProps` is serialized when server rendered.
     * Make sure to return plain `Object` without using `Date`,`Map`,`Set`.
     * @param ctx Context of `page`
     */
    getInitialProps?(context: C): IP | Promise<IP>;
};

在我的_app.tsx中,我希望能够将Layout添加到Component中,例如:

  Component: {
    Layout?: React.FunctionComponent;
  };

是否有一种方法可以从AppProps开始执行此操作,或者我需要先使用AppPropsType扩展/相交Layout,然后重新声明使用扩展的{ {1}}?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)