Skip to content

Commit

Permalink
move reassignment to a type of workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Jun 29, 2024
1 parent 69d0c0a commit 0b0aed8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions typescript_test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,26 @@ untypedStore.dispatch(promiseThunkAction()).then(() => Promise.resolve())

// #248: Need a union overload to handle generic dispatched types
function testIssue248() {
const dispatch: ThunkDispatch<any, unknown, Actions> = store.dispatch

function dispatchWrap(
action: Actions | ThunkAction<any, any, unknown, Actions>
) {
// Should not have an error here thanks to the extra union overload
dispatch(action)

// this errors, because the union overload is not present
// @ts-expect-error
store.dispatch(action)

// workarounds:

// assign to ThunkDispatch type
// Should not have an error here thanks to the extra union overload
const dispatch: ThunkDispatch<any, unknown, Actions> = store.dispatch
dispatch(action)

// old reliable
store.dispatch(action as any)

// non-ideal, but works
typeof action === 'function'
? store.dispatch(action)
: store.dispatch(action)

// or just assign to ThunkDispatch as above
}
}

0 comments on commit 0b0aed8

Please sign in to comment.