Skip to content

Commit

Permalink
Add more type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Feb 9, 2024
1 parent 6905000 commit 57d6f3f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions type-tests/types-reflect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ import { expectType } from 'tsd';
expectType<React.FC>(ReflectedInput);
}

// reflect should not allow wrong props in final types
{
const Input: React.FC<{
value: string;
onChange: (newValue: string) => void;
color: 'red';
}> = () => null;
const $value = createStore<string>('');
const changed = createEvent<string>();

const ReflectedInput = reflect({
view: Input,
bind: {
value: $value,
onChange: changed,
},
});

const App: React.FC = () => {
return (
<ReflectedInput
// @ts-expect-error
color="blue"
/>
);
};
expectType<React.FC>(App);
}

// reflect should allow not-to pass required props - as they can be added later in react
{
const Input: React.FC<{
Expand Down Expand Up @@ -133,6 +162,36 @@ import { expectType } from 'tsd';
expectType<React.FC>(AppFixed);
}

// reflect should not allow to override "binded" props with wrong types
{
const Input: React.FC<{
value: string;
onChange: (newValue: string) => void;
color: 'red';
}> = () => null;
const $value = createStore<string>('');
const changed = createEvent<string>();

const ReflectedInput = reflect({
view: Input,
bind: {
value: $value,
onChange: changed,
color: 'red',
},
});

const App: React.FC = () => {
return (
<ReflectedInput
// @ts-expect-error
color="blue"
/>
);
};
expectType<React.FC>(App);
}

// reflect should allow to pass EventCallable<void> as click event handler
{
const Button: React.FC<{
Expand Down

0 comments on commit 57d6f3f

Please sign in to comment.