Skip to content

Commit 54c1d77

Browse files
Add another example
1 parent 433e525 commit 54c1d77

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

type-tests/types-reflect.tsx

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
import { reflect } from '@effector/reflect';
33
import { Button } from '@mantine/core';
44
import { createEvent, createStore } from 'effector';
5-
import React, { ComponentType, FC, PropsWithChildren, ReactNode } from 'react';
5+
import React, {
6+
AnchorHTMLAttributes,
7+
ButtonHTMLAttributes,
8+
ComponentType,
9+
FC,
10+
LabelHTMLAttributes,
11+
PropsWithChildren,
12+
ReactNode,
13+
} from 'react';
614
import { expectType } from 'tsd';
715

816
// basic reflect
@@ -543,3 +551,54 @@ function localize(value: string): unknown {
543551
}}
544552
/>;
545553
}
554+
555+
// edge-case: polymorphic props
556+
{
557+
interface CommonProps {
558+
inline?: boolean;
559+
progress?: boolean;
560+
enabledOnProgress?: boolean;
561+
floating?: boolean;
562+
showSpinnerIcon?: boolean;
563+
onBright?: boolean;
564+
}
565+
type HTMLButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
566+
interface ButtonButtonProps extends CommonProps, Omit<HTMLButtonProps, 'size'> {
567+
tag?: 'button';
568+
href?: never;
569+
}
570+
type HTMLAnchorProps = AnchorHTMLAttributes<HTMLAnchorElement>;
571+
interface AnchorButtonProps extends CommonProps, HTMLAnchorProps {
572+
tag?: 'a';
573+
}
574+
type HTMLLabelProps = LabelHTMLAttributes<HTMLLabelElement>;
575+
interface LabelButtonProps extends CommonProps, HTMLLabelProps {
576+
tag?: 'label';
577+
disabled?: boolean;
578+
}
579+
type ButtonProps = ButtonButtonProps | AnchorButtonProps | LabelButtonProps;
580+
581+
const TestButton = (props: ButtonProps) => {
582+
return null;
583+
};
584+
585+
const ReflectedTestButton1 = reflect({
586+
view: TestButton,
587+
bind: {
588+
inline: true,
589+
progress: true,
590+
tag: 'a',
591+
href: 'test',
592+
},
593+
});
594+
const ReflectedTestButton2 = reflect({
595+
view: TestButton,
596+
// @ts-expect-error
597+
bind: {
598+
inline: true,
599+
progress: true,
600+
tag: 'button',
601+
href: 'test',
602+
},
603+
});
604+
}

0 commit comments

Comments
 (0)