Skip to content

Commit 6c19745

Browse files
committed
Improve types
1 parent 6a0702e commit 6c19745

File tree

4 files changed

+21
-42
lines changed

4 files changed

+21
-42
lines changed

packages/core/src/keyval.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,20 @@ export function keyval<Input, ModelEnhance, Api, Shape>(
149149
}
150150
| Function,
151151
): Keyval<Input, Input & ModelEnhance, Api, Shape> {
152-
let create;
152+
let create:
153+
| void
154+
| ((config: { onMount: Event<void> }) => {
155+
state: unknown;
156+
api?: unknown;
157+
key: string;
158+
optional?: string[];
159+
});
153160
// @ts-expect-error bad implementation
154161
let getKeyRaw;
155-
let shape, props;
162+
let shape: Shape;
163+
let props;
156164
if (typeof options === 'function') {
157-
create = options;
165+
create = options as any;
158166
} else {
159167
({ key: getKeyRaw, shape = {} as Shape, props, create } = options);
160168
}

packages/core/src/model.ts

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,12 @@ export function model<
3636
create,
3737
}: {
3838
props: Input;
39-
create: (
40-
props: {
41-
[K in keyof Input]: Input[K] extends
42-
| Store<unknown>
43-
| Event<unknown>
44-
| Effect<unknown, unknown, unknown>
45-
? Input[K]
46-
: Input[K] extends StoreDef<infer V>
47-
? Store<V>
48-
: Input[K] extends EventDef<infer V>
49-
? Event<V>
50-
: Input[K] extends EffectDef<infer V, infer D, infer E>
51-
? Effect<V, D, E>
52-
: Input[K] extends (params: infer P) => infer R
53-
? Effect<P, Awaited<R>>
54-
: Store<Input[K]>;
55-
} & {
56-
[K in {
57-
[P in keyof Input]: Input[P] extends Store<unknown> | StoreDef<unknown>
58-
? P
59-
: never;
60-
}[keyof Input] as K extends string
61-
? `$${K}`
62-
: never]: Input[K] extends Store<unknown>
63-
? Input[K]
64-
: Input[K] extends StoreDef<infer V>
65-
? Store<V>
66-
: never;
67-
},
68-
config: { onMount: Event<void> },
69-
) =>
70-
| { state: Output; api: Api }
71-
| { state?: never; api: Api }
72-
| { state: Output; api?: never }
73-
| Output;
39+
create: (config: { onMount: Event<void> }) => {
40+
state: Output;
41+
api?: Api;
42+
key: string;
43+
optional?: string[];
44+
};
7445
}): Model<
7546
Input,
7647
Show<{
@@ -108,7 +79,7 @@ export function model<
10879
create,
10980
propsConfig: props,
11081
output: null as unknown as any,
111-
api: null as unknown as any,
82+
// api: null as unknown as any,
11283
shape,
11384
shapeInited: false,
11485
__lens: {} as any,

packages/core/src/spawn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function spawn<
207207
});
208208
const parentTracking = childInstancesTracking;
209209
childInstancesTracking = [];
210-
const outputs = model.create(normProps, { onMount: onMount! });
210+
const outputs = model.create({ onMount: onMount! });
211211
const childInstances = childInstancesTracking;
212212
childInstancesTracking = parentTracking;
213213
let storeOutputs = {} as any;

packages/core/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import type { Store, Event, Effect, EventCallable, Node } from 'effector';
33
export type Model<Props, Output, Api, Shape> = {
44
type: 'model';
55
// private
6-
create: (props: any, config: { onMount: Event<void> }) => any;
6+
create: (config: { onMount: Event<void> }) => any;
77
// private
88
readonly propsConfig: Props;
99
readonly output: Output;
1010
// private
1111
readonly __lens: Shape;
1212
// private
13-
readonly api: Api;
13+
// readonly api: Api;
1414
shape: Show<
1515
{
1616
[K in keyof Props]: Props[K] extends Store<infer V>

0 commit comments

Comments
 (0)