@@ -88,24 +88,41 @@ describe('ComponentStore types', () => {
88
88
} ) ;
89
89
} ) ;
90
90
91
- describe ( 'infers void' , ( ) => {
92
- it ( 'when argument type is specified as Observable< void> and nothing is passed ' , ( ) => {
93
- const effectTest = `const v = componentStore.effect((e: Observable <void>) => string$ )();` ;
91
+ describe ( 'for void types ' , ( ) => {
92
+ it ( 'when generic type is specified as void the argument is optional ' , ( ) => {
93
+ const effectTest = `const sub = componentStore.effect<void>((e ) => EMPTY )();` ;
94
94
expectSnippet ( effectTest ) . toSucceed ( ) ;
95
- expectSnippet ( effectTest ) . toInfer ( 'v' , 'void' ) ;
95
+ expectSnippet ( effectTest ) . toInfer ( 'sub' , 'Subscription' ) ;
96
+ } ) ;
97
+
98
+ it ( 'when argument type is specified as Observable<void> the argument is optional' , ( ) => {
99
+ const effectTest = `const sub = componentStore.effect((e: Observable<void>) => EMPTY)();` ;
100
+ expectSnippet ( effectTest ) . toSucceed ( ) ;
101
+ expectSnippet ( effectTest ) . toInfer ( 'sub' , 'Subscription' ) ;
96
102
} ) ;
97
103
98
- it ( 'when type is not specified and origin can still be piped' , ( ) => {
99
- // treated as Observable<void> 👇
100
- const effectTest = `const v = componentStore.effect((e) => e.pipe(concatMap(() => of())))();` ;
104
+ it ( 'when type is not specified the argument is optional' , ( ) => {
105
+ const effectTest = `const sub = componentStore.effect((e) => EMPTY)();` ;
101
106
expectSnippet ( effectTest ) . toSucceed ( ) ;
102
- expectSnippet ( effectTest ) . toInfer ( 'v' , 'void' ) ;
107
+ expectSnippet ( effectTest ) . toInfer ( 'sub' , 'Subscription' ) ;
108
+ } ) ;
109
+
110
+ it ( 'when type is specified as void the argument can be a void$' , ( ) => {
111
+ const effectTest = `const sub = componentStore.effect((e: Observable<void>) => EMPTY)(of<void>());` ;
112
+ expectSnippet ( effectTest ) . toSucceed ( ) ;
113
+ expectSnippet ( effectTest ) . toInfer ( 'sub' , 'Subscription' ) ;
114
+ } ) ;
115
+
116
+ it ( 'when type is specified as void the argument can be a void' , ( ) => {
117
+ const effectTest = `const sub = componentStore.effect((e) => EMPTY)({} as unknown as void);` ;
118
+ expectSnippet ( effectTest ) . toSucceed ( ) ;
119
+ expectSnippet ( effectTest ) . toInfer ( 'sub' , 'Subscription' ) ;
103
120
} ) ;
104
121
105
122
it ( 'when generic type is specified as void and origin can still be piped' , ( ) => {
106
- const effectTest = `const v = componentStore.effect<void>((e) => e.pipe(concatMap(() => number$)))();` ;
123
+ const effectTest = `const sub = componentStore.effect<void>((e) => e.pipe(concatMap(() => number$)))();` ;
107
124
expectSnippet ( effectTest ) . toSucceed ( ) ;
108
- expectSnippet ( effectTest ) . toInfer ( 'v ' , 'void ' ) ;
125
+ expectSnippet ( effectTest ) . toInfer ( 'sub ' , 'Subscription ' ) ;
109
126
} ) ;
110
127
} ) ;
111
128
@@ -146,29 +163,17 @@ describe('ComponentStore types', () => {
146
163
) ;
147
164
} ) ;
148
165
166
+ it ( 'when generic type is specified as void and a variable with incorrect type is passed' , ( ) => {
167
+ expectSnippet ( `componentStore.effect<void>((e) => number$)(5);` ) . toFail (
168
+ / A r g u m e n t o f t y p e ' n u m b e r ' i s n o t a s s i g n a b l e t o p a r a m e t e r o f t y p e ' v o i d \| O b s e r v a b l e < v o i d > ' /
169
+ ) ;
170
+ } ) ;
171
+
149
172
it ( 'when generic type is specified as unknown and a variable is not passed' , ( ) => {
150
173
expectSnippet (
151
174
`componentStore.effect<unknown>((e) => number$)();`
152
175
) . toFail ( / E x p e c t e d 1 a r g u m e n t s , b u t g o t 0 / ) ;
153
176
} ) ;
154
-
155
- it ( 'when argument type is specified as Observable<void> and anything is passed' , ( ) => {
156
- expectSnippet (
157
- `componentStore.effect((e: Observable<void>) => string$)(5);`
158
- ) . toFail ( / E x p e c t e d 0 a r g u m e n t s , b u t g o t 1 / ) ;
159
- } ) ;
160
-
161
- it ( 'when type is not specified and anything is passed' , ( ) => {
162
- expectSnippet (
163
- `const sub = componentStore.effect((e) => EMPTY)('string');`
164
- ) . toFail ( / E x p e c t e d 0 a r g u m e n t s , b u t g o t 1 / ) ;
165
- } ) ;
166
-
167
- it ( 'when generic type is specified and anything is passed' , ( ) => {
168
- expectSnippet (
169
- `componentStore.effect<void>((e) => EMPTY)(undefined);`
170
- ) . toFail ( / E x p e c t e d 0 a r g u m e n t s , b u t g o t 1 / ) ;
171
- } ) ;
172
177
} ) ;
173
178
} ) ;
174
179
0 commit comments