Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Provider.useDispatch Errors with TypeScript #173

Closed
fny opened this issue Oct 30, 2020 · 1 comment
Closed

Provider.useDispatch Errors with TypeScript #173

fny opened this issue Oct 30, 2020 · 1 comment

Comments

@fny
Copy link

fny commented Oct 30, 2020

The types for Provider.useDispatch seem broken.

import React, { createProvider } from 'reactn'

interface ProviderState {
  x: number
}

const INITIAL_STATE: ProviderState = {
  x: 0
}

const Provider = createProvider(INITIAL_STATE)

Provider.addReducer('increment', (state, dispatch, x = 0) => ({ 
  x: x + 1
})

export default function () {
    const increment = Provider.useDispatch('increment') // <---- ERROR
    const [ x, ] = Provider.useGlobal('x')

    return (
      <div>
        <p>{}</p>
        <button onClick={() => increment() }>Increment</button>
      </div>
    )
}
ERROR

No overload matches this call.
  Overload 1 of 4, '(reducer: Reducer<ProviderState, Reducers, any[], NewGlobalState<ProviderState>>): Dispatcher<ProviderState, any[]>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'Reducer<ProviderState, Reducers, any[], NewGlobalState<ProviderState>>'.
  Overload 2 of 4, '(reducer: never): Dispatcher<ProviderState, never>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'never'.
@fny fny changed the title Use Dispatch Provider.useDispatch Errors with TypeScript Oct 30, 2020
@quisido
Copy link
Collaborator

quisido commented Nov 3, 2020

Closing this in favor of #174.

@quisido quisido closed this as completed Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants