Skip to content

Commit d248857

Browse files
Try to fix other operators
1 parent 6e2c5c7 commit d248857

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

public-types/reflect.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ export function reflect<
104104
* });
105105
* ```
106106
*/
107-
export function createReflect<Props, Bind extends BindFromProps<Props>>(
108-
component: ComponentType<Props>,
107+
export function createReflect<
108+
View extends ComponentType<any>,
109+
Props extends ComponentProps<View>,
110+
Bind extends BindFromProps<Props>,
111+
>(
112+
component: View,
109113
): (
110114
bind: Bind,
111115
features?: {
@@ -143,7 +147,8 @@ type ReflectedProps<Item, Bind> = Item & PropsifyBind<Bind>;
143147
* ```
144148
*/
145149
export function list<
146-
Props,
150+
View extends ComponentType<any>,
151+
Props extends ComponentProps<View>,
147152
Item,
148153
MapItem extends {
149154
[M in keyof Omit<Props, keyof Bind>]: (item: Item, index: number) => Props[M];
@@ -153,7 +158,7 @@ export function list<
153158
config: ReflectedProps<Item, Bind> extends Props
154159
? {
155160
source: Store<Item[]>;
156-
view: ComponentType<Props>;
161+
view: View;
157162
bind?: Bind;
158163
mapItem?: MapItem;
159164
getKey?: (item: Item) => React.Key;
@@ -165,7 +170,7 @@ export function list<
165170
}
166171
: {
167172
source: Store<Item[]>;
168-
view: ComponentType<Props>;
173+
view: View;
169174
bind?: Bind;
170175
mapItem: MapItem;
171176
getKey?: (item: Item) => React.Key;

type-tests/types-create-reflect.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { createReflect } from '@effector/reflect';
3+
import { Button } from '@mantine/core';
34
import { createEvent, createStore } from 'effector';
45
import React from 'react';
56
import { expectType } from 'tsd';
@@ -24,3 +25,18 @@ import { expectType } from 'tsd';
2425

2526
expectType<React.FC>(ReflectedInput);
2627
}
28+
29+
// Edge-case: Mantine Button with weird polymorphic factory
30+
{
31+
const clicked = createEvent<number>();
32+
33+
const reflectButton = createReflect(Button<'button'>);
34+
35+
const ReflectedButton = reflectButton({
36+
children: 'Click me',
37+
color: 'red',
38+
onClick: (e) => clicked(e.clientX),
39+
});
40+
41+
<ReflectedButton component="button" />;
42+
}

type-tests/types-list.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { list } from '@effector/reflect';
3+
import { Button } from '@mantine/core';
34
import { createEvent, createStore } from 'effector';
45
import React from 'react';
56
import { expectType } from 'tsd';
@@ -179,3 +180,19 @@ import { expectType } from 'tsd';
179180

180181
expectType<React.FC>(List);
181182
}
183+
184+
// Edge-case: Mantine Button with weird polymorphic factory
185+
{
186+
const clicked = createEvent<number>();
187+
188+
const List = list({
189+
source: createStore<string[]>([]),
190+
view: Button<'button'>,
191+
mapItem: {
192+
children: (item) => item,
193+
onClick: (_item) => (e) => clicked(e.clientX),
194+
},
195+
});
196+
197+
expectType<React.FC>(List);
198+
}

type-tests/types-variant.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import { reflect, variant } from '@effector/reflect';
3+
import { Button } from '@mantine/core';
34
import { createEvent, createStore } from 'effector';
45
import React, { FC, PropsWithChildren, ReactNode } from 'react';
56
import { expectType } from 'tsd';
@@ -249,3 +250,28 @@ import { expectType } from 'tsd';
249250
);
250251
};
251252
}
253+
254+
// Edge-case: Mantine Button with weird polymorphic factory (failing)
255+
//
256+
// This case is failing because Button has a weird polymorphic factory
257+
// that is not compatible with `variant` as of now
258+
// Test is left here for the future reference, in case if it will be possible to fix
259+
{
260+
const ReflectedVariant = variant({
261+
source: createStore<'button' | 'a'>('button'),
262+
cases: {
263+
// @ts-expect-error
264+
button: Button<'button'>,
265+
// @ts-expect-error
266+
a: Button<'a'>,
267+
},
268+
});
269+
270+
const IfElseVariant = variant({
271+
if: createStore(true),
272+
// @ts-expect-error
273+
then: Button<'button'>,
274+
// @ts-expect-error
275+
else: Button<'a'>,
276+
});
277+
}

0 commit comments

Comments
 (0)