Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Type improvements #89

Open
gabrielperales opened this issue Oct 29, 2020 · 0 comments
Open

Type improvements #89

gabrielperales opened this issue Oct 29, 2020 · 0 comments
Labels
question Further information is requested

Comments

@gabrielperales
Copy link

gabrielperales commented Oct 29, 2020

Additional Context

Hi Sergio,

I've been playing around with this library and I've been thinking about improving some types.

Right now, action types are not bound to their payload. Wouldn't be better if we can do something like?

const ACTION_NAME = duck.defineType<Payload>('ACTION_NAME')

so when I create an action I don't have to specify the payload type, but the benefit will be that in the reducer I could know the type of the action.

So for example in this code:

// ACTION CREATORS
export const completeSurvey = duck.createAction<number>(SURVEY_COMPLETED)

// REDUCER
const reducer = duck.createReducer<State>({
	[SURVEY_COMPLETED]: (state: State, action: ReturnType<typeof completeSurvey>) => {
		return {
			...state,
			[action.payload]: (new Date()).toString()
		}
	}
}, initialState)

Right now I have to specify that the action is ReturnType<typeof completeSurvey> (TypeScript can't infer the type of the action) but in the other way, TypeScript will be able to do it.

@gabrielperales gabrielperales added the question Further information is requested label Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant