File tree 4 files changed +12
-5
lines changed
packages/vue-apollo-composable
4 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 37
37
},
38
38
"dependencies" : {
39
39
"throttle-debounce" : " ^2.3.0" ,
40
+ "ts-essentials" : " ^8.1.0" ,
40
41
"vue-demi" : " ^0.9.1"
41
42
},
42
43
"peerDependencies" : {
Original file line number Diff line number Diff line change 1
1
import { Ref , computed } from 'vue-demi'
2
2
import { ExtractSingleKey } from './util/ExtractSingleKey'
3
+ import type { DeepNonNullable , DeepRequired } from 'ts-essentials'
3
4
4
5
export type UseResultReturn < T > = Readonly < Ref < Readonly < T > > >
5
6
@@ -60,7 +61,7 @@ export function useResult<
60
61
> (
61
62
result : Ref < TResult > ,
62
63
defaultValue : TDefaultValue | undefined ,
63
- pick : ( data : TResult ) => TReturnValue
64
+ pick : ( data : DeepRequired < DeepNonNullable < TResult > > ) => TReturnValue
64
65
) : UseResultReturn < TDefaultValue | TReturnValue >
65
66
66
67
export function useResult <
@@ -70,14 +71,14 @@ export function useResult<
70
71
> (
71
72
result : Ref < TResult > ,
72
73
defaultValue ?: TDefaultValue ,
73
- pick ?: ( data : TResult ) => TReturnValue ,
74
+ pick ?: ( data : DeepRequired < DeepNonNullable < TResult > > ) => TReturnValue ,
74
75
) : UseResultReturn < TResult | TResult [ keyof TResult ] | TDefaultValue | TReturnValue | undefined > {
75
76
return computed ( ( ) => {
76
77
const value = result . value
77
78
if ( value ) {
78
79
if ( pick ) {
79
80
try {
80
- return pick ( value )
81
+ return pick ( value as DeepRequired < DeepNonNullable < TResult > > )
81
82
} catch ( e ) {
82
83
// Silent error
83
84
}
Original file line number Diff line number Diff line change @@ -107,12 +107,12 @@ const { result: multiKeyResult } = multiKeyQuery
107
107
const useResult_WithPickFunction = useResult (
108
108
multiKeyResult ,
109
109
[ ] as const ,
110
- data => data ? .otherExample ? .__typename ,
110
+ data => data . otherExample . __typename ,
111
111
)
112
112
113
113
assertExactType <
114
114
typeof useResult_WithPickFunction ,
115
- UseResultReturn < 'OtherExample' | [ ] | undefined >
115
+ UseResultReturn < 'OtherExample' | [ ] >
116
116
> ( useResult_WithPickFunction )
117
117
118
118
if ( typeof useResult_WithPickFunction . value === 'string' ) {
Original file line number Diff line number Diff line change @@ -14918,6 +14918,11 @@ tryer@^1.0.1:
14918
14918
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
14919
14919
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
14920
14920
14921
+ ts-essentials@^8.1.0:
14922
+ version "8.1.0"
14923
+ resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-8.1.0.tgz#bc982b242db226b84c89477d3d42630ee2954513"
14924
+ integrity sha512-34xALeQADWRYq9kbtprP4KdpTQ3v3BBIs/U4SpaP+C4++B8ijXY5NnILRJLchQVMzw7YBzKuGMUMrI9uT+ALVw==
14925
+
14921
14926
ts-invariant@^0.4.0:
14922
14927
version "0.4.4"
14923
14928
resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.4.4.tgz#97a523518688f93aafad01b0e80eb803eb2abd86"
You can’t perform that action at this time.
0 commit comments