Skip to content

Commit 41afed3

Browse files
author
Viktor Pasynok
committed
Update dependencies and enhance type inference in payload handling. Closes #11
1 parent 2940d07 commit 41afed3

File tree

5 files changed

+150
-83
lines changed

5 files changed

+150
-83
lines changed

package-lock.json

Lines changed: 81 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"author": "Viktor Pasynok",
1111
"license": "MIT",
1212
"devDependencies": {
13-
"@rslib/core": "0.17.0",
13+
"@rslib/core": "0.17.1",
1414
"@size-limit/preset-small-lib": "11.2.0",
1515
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
1616
"clean-publish": "6.0.1",
17+
"patronum": "2.3.0",
1718
"prettier": "3.6.2",
1819
"prettier-plugin-organize-imports": "4.3.0",
1920
"size-limit": "11.2.0",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { createEffect, createEvent, createStore } from 'effector';
2+
import { expectTypeOf } from 'vitest';
3+
import { ExtractWhenPayload } from '../payload';
4+
5+
const event = createEvent<string>();
6+
const $store = createStore<number>(0);
7+
const effectFx = createEffect<boolean, void>();
8+
const effectWithArrayFx = createEffect<string[], void>();
9+
10+
// --- Single Units ---
11+
12+
expectTypeOf<ExtractWhenPayload<typeof event>>().toEqualTypeOf<string>();
13+
expectTypeOf<ExtractWhenPayload<typeof $store>>().toEqualTypeOf<number>();
14+
expectTypeOf<ExtractWhenPayload<typeof effectFx>>().toEqualTypeOf<boolean>();
15+
expectTypeOf<ExtractWhenPayload<typeof effectWithArrayFx>>().toEqualTypeOf<string[]>();
16+
17+
// --- Array of Units ---
18+
19+
// Single type array
20+
expectTypeOf<ExtractWhenPayload<[typeof event]>>().toEqualTypeOf<string>();
21+
expectTypeOf<ExtractWhenPayload<[typeof $store]>>().toEqualTypeOf<number>();
22+
expectTypeOf<ExtractWhenPayload<[typeof effectFx]>>().toEqualTypeOf<boolean>();
23+
expectTypeOf<ExtractWhenPayload<[typeof effectWithArrayFx]>>().toEqualTypeOf<string[]>();
24+
25+
// Mixed array
26+
expectTypeOf<
27+
ExtractWhenPayload<[typeof event, typeof $store, typeof effectFx, typeof effectWithArrayFx]>
28+
>().toEqualTypeOf<string | number | boolean | string[]>();
29+
30+
// Mixed array with duplicates
31+
expectTypeOf<ExtractWhenPayload<[typeof event, typeof event, typeof $store]>>().toEqualTypeOf<string | number>();
32+
33+
// --- Edge Cases ---
34+
35+
// Empty array should resolve to never
36+
expectTypeOf<ExtractWhenPayload<[]>>().toBeNever();
37+
38+
// Non-unit types should resolve to never
39+
expectTypeOf<ExtractWhenPayload<string>>().toBeNever();
40+
expectTypeOf<ExtractWhenPayload<number>>().toBeNever();
41+
expectTypeOf<ExtractWhenPayload<null>>().toBeNever();
42+
expectTypeOf<ExtractWhenPayload<undefined>>().toBeNever();
43+
expectTypeOf<ExtractWhenPayload<{ a: 1 }>>().toBeNever();

0 commit comments

Comments
 (0)