@@ -23,20 +23,24 @@ interface Config<S, U> extends Partial<ScopeConfig> {
23
23
selector ?: ( state : S ) => U
24
24
}
25
25
26
- export function useAyanami < M extends Ayanami < S > , S , U = M extends Ayanami < infer SS > ? SS : S > (
26
+ export function useAyanami < M extends Ayanami < any > , U = M extends Ayanami < infer S > ? S : never > (
27
27
A : ConstructorOf < M > ,
28
- config ?: M extends Ayanami < infer SS > ? Config < SS , U > : Config < S , U > ,
29
- ) : M extends Ayanami < infer SS > ? Result < M , SS , U > : Result < M , S , U > {
28
+ config ?: M extends Ayanami < infer S > ? Config < S , U > : never ,
29
+ ) : M extends Ayanami < infer S >
30
+ ? NonNullable < typeof config > extends Config < S , infer SS >
31
+ ? Result < M , S , SS >
32
+ : Result < M , S , S >
33
+ : never {
30
34
const scope = get ( config , 'scope' )
31
35
const selector = get ( config , 'selector' )
32
36
const req = isSSREnabled ( ) ? React . useContext ( SSRContext ) : null
33
37
const reqScope = req ? createScopeWithRequest ( req , scope ) : scope
34
38
const ayanami = React . useMemo ( ( ) => getInstanceWithScope ( A , reqScope ) , [ reqScope ] )
35
39
ayanami . scopeName = scope || DEFAULT_SCOPE_NAME
36
40
37
- const useAyanamiInstanceConfig = React . useMemo ( ( ) : UseAyanamiInstanceConfig < S , U > => {
41
+ const useAyanamiInstanceConfig = React . useMemo < UseAyanamiInstanceConfig > ( ( ) => {
38
42
return { destroyWhenUnmount : scope === TransientScope , selector }
39
43
} , [ reqScope ] )
40
44
41
- return useAyanamiInstance < M , S , U > ( ayanami , useAyanamiInstanceConfig ) as any
45
+ return useAyanamiInstance ( ayanami , useAyanamiInstanceConfig ) as any
42
46
}
0 commit comments