fix:修复无法推导组件

This commit is contained in:
ningmengchongshui 2024-06-18 13:46:21 +08:00
parent 16acf39012
commit b96ba6aac5
1 changed files with 18 additions and 1 deletions

View File

@ -59,6 +59,23 @@ export type ModuleWithComponent<
PropsType = any
> = Promise<{ [K in ComponentName]: React.ComponentType<PropsType> }>
// export const createDynamicComponent = (basePath: string) => {
// /**
// * 与import作用相同
// * @param path 相对路径
// * @returns
// */
// return <T extends Record<string, any> = { default: any }>(
// path: string
// ): Promise<{ [K in keyof T]: React.ComponentType<T[K]> }> =>
// import(
// new URL(
// `${path}${process.env.NODE_ENV == 'production' ? '' : now()}`,
// basePath
// ).href
// )
// }
/**
* @param basePath import.meta.url
* @returns
@ -73,7 +90,7 @@ export const createDynamicComponent = (basePath: string) => {
* @param path
* @returns
*/
return <D extends string, T = any>(path: string): ModuleWithComponent<D, T> =>
return <T>(path: string): Promise<T> =>
import(
new URL(
`${path}${process.env.NODE_ENV == 'production' ? '' : now()}`,