Skip to content

Commit 8066268

Browse files
committed
fix: try to fix invalid typings for withLazyViewModel HOC
1 parent a9cbe34 commit 8066268

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/hoc/with-lazy-view-model.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
import { ComponentType } from 'react';
1+
import { ComponentProps, ComponentType, ReactNode } from 'react';
22
import { loadable } from 'react-simple-loadable';
33

44
import { Class } from '../utils/types';
5+
import { ViewModel } from '../view-model';
56

6-
import { ViewModelHocConfig, withViewModel } from './with-view-model';
7+
import {
8+
ViewModelHocConfig,
9+
ViewModelInputProps,
10+
withViewModel,
11+
} from './with-view-model';
712

8-
interface LazyViewAndModel {
9-
Model: Class<any>;
10-
View: ComponentType<any>;
13+
interface LazyViewAndModel<
14+
TViewModel extends ViewModel<any>,
15+
TView extends ComponentType<any>,
16+
> {
17+
Model: Class<TViewModel>;
18+
View: TView;
1119
}
1220

13-
export function withLazyViewModel(
14-
loadFunction: () => Promise<LazyViewAndModel>,
21+
export function withLazyViewModel<
22+
TViewModel extends ViewModel<any>,
23+
TView extends ComponentType<any>,
24+
>(
25+
loadFunction: () => Promise<LazyViewAndModel<TViewModel, TView>>,
1526
config?: ViewModelHocConfig<any>,
1627
) {
1728
return loadable(async () => {
1829
const { Model, View } = await loadFunction();
1930
return withViewModel(Model, config)(View);
20-
}, config?.fallback);
31+
}, config?.fallback) as unknown as (
32+
props: Omit<ComponentProps<TView>, 'model'> &
33+
ViewModelInputProps<TViewModel>,
34+
) => ReactNode;
2135
}

0 commit comments

Comments
 (0)