|
1 | 1 | import React from 'react'; |
2 | 2 | import { expectTypeOf } from 'vitest'; |
3 | | -import { type Payload } from '../init'; |
| 3 | +import { createSlotIdentifier, createSlots, type EmptyObject } from '../init'; |
4 | 4 |
|
5 | | -type EmptyObject = Record<string, never>; |
| 5 | +const slotId = createSlotIdentifier<{ text: string }>(); |
| 6 | +const noPropsSlot = createSlotIdentifier<void>(); |
6 | 7 |
|
7 | | -declare const payload: Payload<{ name: string }>; |
| 8 | +const { slotsApi } = createSlots({ |
| 9 | + Top: slotId, |
| 10 | + Bottom: noPropsSlot, |
| 11 | +}); |
8 | 12 |
|
9 | | -payload({ |
10 | | - fn: (data) => ({ label: data.name }), |
| 13 | +slotsApi.insert.into.Top({ |
| 14 | + fn: (data) => ({ text: data.text }), |
11 | 15 | component: (props) => { |
12 | | - expectTypeOf<{ label: string }>(props); |
| 16 | + expectTypeOf<{ text: string }>(props); |
13 | 17 | return <div />; |
14 | 18 | }, |
15 | 19 | }); |
16 | 20 |
|
17 | | -payload({ |
| 21 | +slotsApi.insert.into.Top({ |
18 | 22 | component: (props) => { |
19 | 23 | expectTypeOf<EmptyObject>(props); |
20 | 24 | return <div />; |
21 | 25 | }, |
22 | 26 | }); |
23 | 27 |
|
24 | | -payload({ |
| 28 | +slotsApi.insert.into.Top({ |
25 | 29 | fn: () => {}, |
26 | 30 | component: (props) => { |
27 | 31 | expectTypeOf<EmptyObject>(props); |
28 | 32 | return <div />; |
29 | 33 | }, |
30 | 34 | }); |
31 | 35 |
|
32 | | -payload({ |
33 | | - fn: (data) => ({ label: data.name }), |
34 | | - // @ts-expect-error expected { label: string } but got { wrong: number } |
| 36 | +slotsApi.insert.into.Bottom({ |
| 37 | + component: (props) => { |
| 38 | + expectTypeOf<EmptyObject>(props); |
| 39 | + return <div />; |
| 40 | + }, |
| 41 | +}); |
| 42 | + |
| 43 | +slotsApi.insert.into.Top({ |
| 44 | + fn: (data) => ({ text: data.text }), |
| 45 | + // @ts-expect-error |
35 | 46 | component: (_: { wrong: number }) => <div />, |
36 | 47 | }); |
0 commit comments