CharlesStover/reactn

Provider.useDispatch Errors with TypeScript

fny opened this issue · 1 comments

fny commented

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'.

Closing this in favor of #174.