Repository: effector/effector (ts)

Issue:
createAPI broken types
<!--
Found a bug? Please fill out the sections below.
Be kind and objective when writing in text. Thanks!
-->

**What is the current behavior:**

TypeScript errors when I try to return undefined from the event created with createApi.

**Please provide the steps to reproduce and if possible a minimal demo of the problem via https://share.effector.dev, https://codesandbox.io or similar**

https://codesandbox.io/s/focused-bird-zke04?file=/src/index.ts

**What is the expected behavior:**

No TypeScript error :) 

**Which versions of effector packages, and which browser and OS are affected by this issue? Did this work in previous 
versions of effector?:**

effector@21.8.8


Pull request description:
fix return type of reducer for createApi
close #468 

Patch:
diff --git a/packages/effector/index.d.ts b/packages/effector/index.d.ts
index e3a73e2a..a248254e 100644
--- a/packages/effector/index.d.ts
+++ b/packages/effector/index.d.ts
@@ -288,7 +288,7 @@ export class Domain implements Unit<any> {
   createStore<State>(
     defaultState: State,
     config?: {
-      name?: string 
+      name?: string
       sid?: string
       updateFilter?: (update: State, current: State) => boolean
     },
@@ -542,7 +542,7 @@ export function split<
 
 export function createApi<
   S,
-  Api extends {[name: string]: (store: S, e: any) => S}
+  Api extends {[name: string]: (store: S, e: any) => S | void}
 >(
   store: Store<S>,
   api: Api,
@@ -620,7 +620,7 @@ type UnitObject = Store<any> | Event<any> | Effect<any, any, any> | Unit<any>
 
 /**
  * Force typescript to print real type instead of geneic types
- * 
+ *
  * It's better to see {a: string; b: number}
  * instead of GetCombinedValue<{a: Store<string>; b: Store<number>}>
  * */
@@ -1299,11 +1299,11 @@ export function attach<
 }): Effect<Params, EffectResult<FX>, EffectError<FX>>
 export function attach<FN extends ((params: any) => any), FX extends Effect<any, any, any>>(config: {
   effect: FX
-  mapParams: FN extends (...args: any[]) => NoInfer<EffectParams<FX>> 
+  mapParams: FN extends (...args: any[]) => NoInfer<EffectParams<FX>>
     ? FN
     : never
   name?: string
-}): FN extends (...args: infer Args) => NoInfer<EffectParams<FX>> 
+}): FN extends (...args: infer Args) => NoInfer<EffectParams<FX>>
   ? Effect<
     Args['length'] extends 0
       ? void


Test patch:
diff --git a/src/types/__tests__/effector/createApi.test.ts b/src/types/__tests__/effector/createApi.test.ts
index 3e761686..5ca03001 100644
--- a/src/types/__tests__/effector/createApi.test.ts
+++ b/src/types/__tests__/effector/createApi.test.ts
@@ -101,6 +101,21 @@ test('createApi void calls edge case (should pass)', () => {
   `)
 })
 
+test('createApi returns nothing from reducer (should pass)', () => {
+  const $isLoading = createStore(false)
+  const {start} = createApi($isLoading, {
+    start: (_, p) => p === 1 ? true : undefined,
+  })
+
+  start()
+
+  expect(typecheck).toMatchInlineSnapshot(`
+    "
+    no errors
+    "
+  `)
+})
+
 describe('type validation', () => {
   test('correct call (should pass)', () => {
     const x = createStore(0)