(state: State, event: Event)
| 100 | }; |
| 101 | |
| 102 | const reducer = (state: State, event: Event): State => |
| 103 | match<[State, Event], State>([state, event]) |
| 104 | .with( |
| 105 | [ |
| 106 | { status: 'loading' }, |
| 107 | { |
| 108 | type: 'success', |
| 109 | data: P.select('data'), |
| 110 | requestTime: P.select('time'), |
| 111 | }, |
| 112 | ], |
| 113 | ({ data, time }) => { |
| 114 | type t = Expect<Equal<typeof time, number | undefined>>; |
| 115 | |
| 116 | return { |
| 117 | status: 'success', |
| 118 | data, |
| 119 | }; |
| 120 | } |
| 121 | ) |
| 122 | .with( |
| 123 | [{ status: 'loading' }, { type: 'success', data: P.select('data') }], |
| 124 | ({ data }) => ({ |
| 125 | status: 'success', |
| 126 | data, |
| 127 | }) |
| 128 | ) |
| 129 | .with( |
| 130 | [{ status: 'loading' }, { type: 'error', error: P.select('error') }], |
| 131 | ({ error }) => ({ |
| 132 | status: 'error', |
| 133 | error, |
| 134 | }) |
| 135 | ) |
| 136 | .with([{ status: 'loading' }, { type: 'cancel' }], () => initState) |
| 137 | .with([{ status: P.not('loading') }, { type: 'fetch' }], () => ({ |
| 138 | status: 'loading', |
| 139 | })) |
| 140 | .with([P.select('state'), P.select('event')], ({ state, event }) => { |
| 141 | type t = Expect<Equal<typeof state, State>>; |
| 142 | type t2 = Expect<Equal<typeof event, Event>>; |
| 143 | return state; |
| 144 | }) |
| 145 | .run(); |
| 146 | |
| 147 | expect(reducer(initState, { type: 'cancel' })).toEqual(initState); |
| 148 |
no test coverage detected
searching dependent graphs…